| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Services\FormBuilder\Components; |
| 4 |
|
| 5 |
use FluentForm\Framework\Helpers\ArrayHelper; |
| 6 |
|
| 7 |
class Text extends BaseComponent |
| 8 |
{ |
| 9 |
/** |
| 10 |
* Compile and echo the html element |
| 11 |
* @param array $data [element data] |
| 12 |
* @param stdClass $form [Form Object] |
| 13 |
* @return viod |
| 14 |
*/ |
| 15 |
public function compile($data, $form) |
| 16 |
{ |
| 17 |
$elementName = $data['element']; |
| 18 |
$data = apply_filters('fluenform_rendering_field_data_'.$elementName, $data, $form); |
| 19 |
|
| 20 |
// </mask input> |
| 21 |
if ( isset($data['settings']['temp_mask']) && $data['settings']['temp_mask'] != 'custom' ) { |
| 22 |
$data['attributes']['data-mask'] = $data['settings']['temp_mask']; |
| 23 |
} |
| 24 |
|
| 25 |
if(ArrayHelper::get($data, 'settings.temp_mask') == 'custom') { |
| 26 |
if(ArrayHelper::get($data, 'settings.data-mask-reverse') == 'yes') { |
| 27 |
$data['attributes']['data-mask-reverse'] = 'true'; |
| 28 |
} |
| 29 |
|
| 30 |
if(ArrayHelper::get($data, 'settings.data-clear-if-not-match') == 'yes') { |
| 31 |
$data['attributes']['data-clear-if-not-match'] = 'true'; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
if(isset($data['attributes']['data-mask'])) { |
| 36 |
wp_enqueue_script( |
| 37 |
'jquery-mask', |
| 38 |
$this->app->publicUrl('libs/jquery.mask.min.js'), |
| 39 |
array('jquery'), |
| 40 |
false, |
| 41 |
true |
| 42 |
); |
| 43 |
} |
| 44 |
|
| 45 |
if($data['element'] == 'input_number' || $data['element'] = 'custom_payment_component') { |
| 46 |
if( |
| 47 |
ArrayHelper::get($data, 'settings.calculation_settings.status') && |
| 48 |
$formula = ArrayHelper::get($data, 'settings.calculation_settings.formula') |
| 49 |
) { |
| 50 |
$data['attributes']['data-calculation_formula'] = $formula; |
| 51 |
$data['attributes']['class'] .= ' ff_has_formula'; |
| 52 |
$data['attributes']['readonly'] = true; |
| 53 |
$data['attributes']['type'] = 'text'; |
| 54 |
|
| 55 |
add_filter('fluentform_form_class', function ($css_class , $targetForm) use ($form) { |
| 56 |
if($targetForm->id == $form->id) { |
| 57 |
$css_class .= ' ff_calc_form'; |
| 58 |
} |
| 59 |
return $css_class; |
| 60 |
}, 10, 2); |
| 61 |
|
| 62 |
do_action('ff_rendering_calculation_form', $form, $data); |
| 63 |
} else { |
| 64 |
if(!apply_filters('fluentform_disable_inputmode', false)) { |
| 65 |
$data['attributes']['inputmode'] = 'numeric'; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
if($step = ArrayHelper::get($data, 'settings.number_step')) { |
| 70 |
$data['attributes']['step'] = $step; |
| 71 |
} else if(ArrayHelper::get($data, 'attributes.type') == 'number') { |
| 72 |
$data['attributes']['step'] = 'any'; |
| 73 |
} |
| 74 |
|
| 75 |
$min = ArrayHelper::get($data, 'settings.validation_rules.min.value'); |
| 76 |
if($min || $min == 0) { |
| 77 |
$data['attributes']['min'] = $min; |
| 78 |
} |
| 79 |
|
| 80 |
if($max = ArrayHelper::get($data, 'settings.validation_rules.max.value')) { |
| 81 |
$data['attributes']['max'] = $max; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
// For hidden input |
| 87 |
if ($data['attributes']['type'] == 'hidden') { |
| 88 |
echo "<input ".$this->buildAttributes($data['attributes'], $form).">"; |
| 89 |
return; |
| 90 |
} |
| 91 |
|
| 92 |
if($tabIndex = \FluentForm\App\Helpers\Helper::getNextTabIndex()) { |
| 93 |
$data['attributes']['tabindex'] = $tabIndex; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
$data['attributes']['class'] = @trim('ff-el-form-control '. $data['attributes']['class']); |
| 98 |
$data['attributes']['id'] = $this->makeElementId($data, $form); |
| 99 |
|
| 100 |
$elMarkup = $this->buildInputGroup($data, $form); |
| 101 |
|
| 102 |
$html = $this->buildElementMarkup($elMarkup, $data, $form); |
| 103 |
echo apply_filters('fluenform_rendering_field_html_'.$elementName, $html, $data, $form); |
| 104 |
} |
| 105 |
|
| 106 |
private function buildInputGroup($data, $form) |
| 107 |
{ |
| 108 |
$input = "<input ".$this->buildAttributes($data['attributes'], $form).">"; |
| 109 |
$prefix = ArrayHelper::get($data, 'settings.prefix_label'); |
| 110 |
$suffix = ArrayHelper::get($data, 'settings.suffix_label'); |
| 111 |
if($prefix || $suffix) { |
| 112 |
$wrapper = '<div class="ff_input-group">'; |
| 113 |
if($prefix) { |
| 114 |
$wrapper .= '<div class="ff_input-group-prepend"><span class="ff_input-group-text">'.$prefix.'</span></div>'; |
| 115 |
} |
| 116 |
$wrapper .= $input; |
| 117 |
if($suffix) { |
| 118 |
$wrapper .= '<div class="ff_input-group-append"><span class="ff_input-group-text">'.$suffix.'</span></div>'; |
| 119 |
} |
| 120 |
$wrapper .= '</div>'; |
| 121 |
return $wrapper; |
| 122 |
} |
| 123 |
return $input; |
| 124 |
} |
| 125 |
|
| 126 |
} |
| 127 |
|