Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lite Version: Add Currency Settings to Number Field and Apply Enhancements #1864

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions classes/controllers/FrmFieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,17 @@ public static function display_field_options( $settings, $field_info = null ) {
*
* @since 3.0
*
* @param array $field
* @param array $field Field array.
* @param bool $is_hidden Whether the format option should be hidden.
* @return void
*/
public static function show_format_option( $field ) {
$attributes = array();
$attributes['class'] = 'frm-has-modal';
public static function show_format_option( $field, $is_hidden = false ) {
$attributes = array(
'class' => 'frm-has-modal',
'id' => 'phone' === $field['type'] ? 'frm-phone-field-custom-format-' . $field['id'] : 'frm-field-format-custom-' . $field['id'],
);

if ( 'phone' === $field['type'] ) {
$attributes['id'] = 'frm-phone-field-custom-format-' . $field['id'];
if ( $is_hidden ) {
$attributes['class'] .= ' frm_hidden';
}

Expand Down
2 changes: 1 addition & 1 deletion classes/models/fields/FrmFieldPhone.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function show_primary_options( $args ) {
$field = $args['field'];

include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/phone/phone-type.php';
FrmFieldsController::show_format_option( $field );
FrmFieldsController::show_format_option( $field, true );

parent::show_primary_options( $args );
}
Expand Down
20 changes: 20 additions & 0 deletions classes/models/fields/FrmFieldText.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,24 @@ public function validate( $args ) {

return $errors;
}

/**
* Print the format number option for a field.
*
* @since x.x
*
* @return void
*/
public function print_format_number_option( $field ) {
?>
<option
value=""
class="frm_show_upgrade frm_noallow"
data-upgrade="<?php esc_attr_e( 'Format number field', 'formidable' ); ?>"
data-medium="format-number-field"
>
<?php esc_html_e( 'Number', 'formidable' ); ?>
</option>
<?php
}
}
21 changes: 21 additions & 0 deletions classes/models/fields/FrmFieldTextarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected function field_settings_for_type() {
return array(
'size' => true,
'clear_on_focus' => true,
'format' => true,
);
}

Expand Down Expand Up @@ -97,4 +98,24 @@ public function front_field_input( $args, $shortcode_atts ) {
FrmAppHelper::esc_textarea( $this->field['value'] ) .
'</textarea>';
}

/**
* Print the format number option for a field.
*
* @since x.x
*
* @return void
*/
public function print_format_number_option( $field ) {
?>
<option
value=""
class="frm_show_upgrade frm_noallow"
data-upgrade="<?php esc_attr_e( 'Format number field', 'formidable' ); ?>"
data-medium="format-number-field"
>
<?php esc_html_e( 'Number', 'formidable' ); ?>
</option>
<?php
}
}
39 changes: 39 additions & 0 deletions classes/views/frm-fields/back-end/format-type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* @package Formidable
* @since x.x
*
* @var array $field Field array.
* @var array $args Includes 'field', 'display', and 'values' settings.
* @var FrmFieldType $this Field type object.
*/

if ( ! defined( 'ABSPATH' ) ) {
die( 'You are not allowed to call this page directly.' );
}

$field_id = $field['id'];
$format = FrmField::get_option( $field, 'format' );
?>
<p class="frm6 frm6_followed frm_form_field frm-format-type">
<label for="format_type_<?php echo esc_attr( $field_id ); ?>">
<?php esc_html_e( 'Format', 'formidable' ); ?>
</label>

<select
name="field_options[format_type_<?php echo esc_attr( $field_id ); ?>]"
id="format_type_<?php echo esc_attr( $field_id ); ?>"
class="frm_format_type_dropdown frm_select_with_upgrade frm_select_with_dependency"
data-field-id="<?php echo intval( $field_id ); ?>"
>
<option value="none" <?php selected( $format, '' ); ?>>
<?php esc_html_e( 'None', 'formidable' ); ?>
</option>

<?php FrmFieldFactory::get_field_type( $field['type'] )->print_format_number_option( $field ); ?>

Check failure on line 33 in classes/views/frm-fields/back-end/format-type.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to an undefined method FrmFieldType::print_format_number_option().

Check failure on line 33 in classes/views/frm-fields/back-end/format-type.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedMethod

classes/views/frm-fields/back-end/format-type.php:33:60: UndefinedMethod: Method FrmFieldType::print_format_number_option does not exist (see https://psalm.dev/022)

<option value="custom" data-dependency="#frm-field-format-custom-<?php echo esc_attr( $field_id ); ?>" <?php selected( ! empty( $format ) && 'number' !== $format, true ); ?>>
<?php esc_html_e( 'Custom', 'formidable' ); ?>
</option>
</select>
</p>
45 changes: 25 additions & 20 deletions classes/views/frm-fields/back-end/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,41 @@
<input type="hidden" name="field_options[name_<?php echo esc_attr( $field['id'] ); ?>]" value="<?php echo esc_attr( $field['name'] ); ?>" id="frm_name_<?php echo esc_attr( $field['id'] ); ?>" />
<?php } ?>

<p class="frm-hide-empty">
<div class="frm-hide-empty frm-inline-flex frm-gap-sm frm-flex-wrap frm-items-center frm-my-xs">
<?php if ( $display['required'] ) { ?>
<label for="frm_req_field_<?php echo esc_attr( $field['id'] ); ?>" class="frm_inline_label">
<input type="checkbox" id="frm_req_field_<?php echo esc_attr( $field['id'] ); ?>" class="frm_req_field" name="field_options[required_<?php echo esc_attr( $field['id'] ); ?>]" value="1" <?php checked( $field['required'], 1 ); ?> />
<?php esc_html_e( 'Required', 'formidable' ); ?>
</label>
<div class="frm_form_field">
<label for="frm_req_field_<?php echo esc_attr( $field['id'] ); ?>" class="frm-mb-0">
<input type="checkbox" id="frm_req_field_<?php echo esc_attr( $field['id'] ); ?>" class="frm_req_field" name="field_options[required_<?php echo esc_attr( $field['id'] ); ?>]" value="1" <?php checked( $field['required'], 1 ); ?> />
<?php esc_html_e( 'Required', 'formidable' ); ?>
</label>
</div>
<?php
}

if ( $display['unique'] ) {
?>
<label for="frm_uniq_field_<?php echo esc_attr( $field['id'] ); ?>" class="frm_inline_label frm_help" title="<?php esc_attr_e( 'Unique: Do not allow the same response multiple times. For example, if one user enters \'Joe\', then no one else will be allowed to enter the same name.', 'formidable' ); ?>"><input type="checkbox" name="field_options[unique_<?php echo esc_attr( $field['id'] ); ?>]" id="frm_uniq_field_<?php echo esc_attr( $field['id'] ); ?>" value="1" <?php checked( $field['unique'], 1 ); ?> class="frm_mark_unique" />
<?php esc_html_e( 'Unique', 'formidable' ); ?>
</label>
<div class="frm_form_field">
<label for="frm_uniq_field_<?php echo esc_attr( $field['id'] ); ?>" class="frm_help frm-mb-0" title="<?php esc_attr_e( 'Unique: Do not allow the same response multiple times. For example, if one user enters \'Joe\', then no one else will be allowed to enter the same name.', 'formidable' ); ?>"><input type="checkbox" name="field_options[unique_<?php echo esc_attr( $field['id'] ); ?>]" id="frm_uniq_field_<?php echo esc_attr( $field['id'] ); ?>" value="1" <?php checked( $field['unique'], 1 ); ?> class="frm_mark_unique" />
<?php esc_html_e( 'Unique', 'formidable' ); ?>
</label>
</div>
<?php
}

if ( $display['read_only'] ) {
?>
<label for="frm_read_only_field_<?php echo esc_attr( $field['id'] ); ?>" class="frm_inline_label frm_help" title="<?php esc_attr_e( 'Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable' ); ?>" >
<input type="checkbox" id="frm_read_only_field_<?php echo esc_attr( $field['id'] ); ?>" name="field_options[read_only_<?php echo esc_attr( $field['id'] ); ?>]" value="1" <?php checked( $field['read_only'], 1 ); ?>/>
<?php esc_html_e( 'Read Only', 'formidable' ); ?>
</label>
<div class="frm_form_field">
<label for="frm_read_only_field_<?php echo esc_attr( $field['id'] ); ?>" class="frm_help frm-mb-0" title="<?php esc_attr_e( 'Read Only: Show this field but do not allow the field value to be edited from the front-end.', 'formidable' ); ?>" >
<input type="checkbox" id="frm_read_only_field_<?php echo esc_attr( $field['id'] ); ?>" name="field_options[read_only_<?php echo esc_attr( $field['id'] ); ?>]" value="1" <?php checked( $field['read_only'], 1 ); ?>/>
<?php esc_html_e( 'Read Only', 'formidable' ); ?>
</label>
</div>
<?php
}

do_action( 'frm_field_options_form_top', $field, $display, $values );
?>
</p>
</div>

<?php
if ( $display['range'] ) {
Expand All @@ -101,6 +107,11 @@

$field_obj->show_primary_options( compact( 'field', 'display', 'values' ) );

if ( $display['format'] ) {
include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/back-end/format-type.php';

FrmFieldsController::show_format_option( $field, true );
}
?>

<?php if ( $display['css'] ) { ?>
Expand Down Expand Up @@ -254,13 +265,7 @@
</p>
<?php } ?>

<?php
if ( $display['format'] ) {
FrmFieldsController::show_format_option( $field );
}

do_action( 'frm_field_options', compact( 'field', 'display', 'values' ) );
?>
<?php do_action( 'frm_field_options', compact( 'field', 'display', 'values' ) ); ?>

<?php if ( $display['required'] ) { ?>
<p class="frm6 frm_form_field frm_required_details<?php echo esc_attr( $field['id'] . ( $field['required'] ? '' : ' frm_hidden' ) ); ?>">
Expand Down
2 changes: 2 additions & 0 deletions classes/views/frm-settings/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@

<div class="clear"></div>

<h3><?php esc_html_e( 'Other', 'formidable' ); ?></h3>

<?php if ( ! FrmAppHelper::pro_is_installed() ) { ?>
<input type="hidden" name="frm_menu" id="frm_menu" value="<?php echo esc_attr( $frm_settings->menu ); ?>"/>
<input type="hidden" name="frm_mu_menu" id="frm_mu_menu" value="<?php echo esc_attr( $frm_settings->mu_menu ); ?>"/>
Expand Down
24 changes: 24 additions & 0 deletions css/frm_admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ body.frm-white-body ul#adminmenu > li.current > a.current:after {
grid-column: span 6 / span 6;
}

.frm_form_field.frm12_followed + p,
.frm_form_field.frm12_followed + div {
grid-column: span 12 / span 12 !important;
}

.frm_form_field.frm-phone-type + p > label,
.frm_form_field.frm-phone-type + div > label {
opacity: 0; /* Hide the label for the format input in the phone field. */
Expand Down Expand Up @@ -1721,6 +1726,16 @@ input.frm_insert_in_template {
margin-right: var(--gap-sm) !important;
}

.frm-my-xs {
margin-top: var(--gap-xs) !important;
margin-bottom: var(--gap-xs) !important;
}

#wpbody-content .frm-my-sm {
margin-top: var(--gap-sm) !important;
margin-bottom: var(--gap-sm) !important;
}

.frm-p-0 {
padding: 0 !important;
}
Expand Down Expand Up @@ -1867,6 +1882,10 @@ input.frm_insert_in_template {
display: flex;
}

#wpbody-content .frm-inline-flex {
display: inline-flex;
}

.frm_hidden,
.js .frm-hide-js {
display: none;
Expand Down Expand Up @@ -1937,6 +1956,10 @@ input.frm_insert_in_template {
align-items: center;
}

#wpbody-content .frm-flex-wrap {
flex-wrap: wrap;
}

.frm-transition-ease {
transition: all .2s ease;
}
Expand Down Expand Up @@ -1981,6 +2004,7 @@ input.frm_insert_in_template {
/* End Generic Classes, Start Forced Generic Classes */

.frm-fields p > label.frm_hidden,
#wpbody-content label.frm_hidden,
.frm-lookup-modal .dismiss,
.frm-right-panel .inside a.frm_hidden,
#form_global_settings .frm_hidden,
Expand Down
Loading