button.php
2 weeks ago
form-end.php
2 weeks ago
form-field.php
2 weeks ago
form-label.php
2 weeks ago
form-start.php
2 weeks ago
header.php
2 weeks ago
input-checkbox.php
2 weeks ago
input-date-picker.php
2 weeks ago
input-hidden.php
2 weeks ago
input-image.php
2 weeks ago
input-number.php
2 weeks ago
input-radio.php
2 weeks ago
input-submit.php
2 weeks ago
input-text-multiple.php
2 weeks ago
input-text.php
2 weeks ago
input.php
2 weeks ago
noonce.php
2 weeks ago
paragraph.php
2 weeks ago
product-select.php
2 weeks ago
select.php
2 weeks ago
textarea.php
2 weeks ago
wyswig.php
2 weeks ago
input-text-multiple.php
175 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FSVendor; |
| 4 | |
| 5 | /** |
| 6 | * @var \WPDesk\Forms\Field $field |
| 7 | * @var \WPDesk\View\Renderer\Renderer $renderer |
| 8 | * @var string $name_prefix |
| 9 | * @var string $value |
| 10 | * @var string $template_name Real field template. |
| 11 | */ |
| 12 | if (empty($value) || \is_string($value)) { |
| 13 | $input_values[] = ''; |
| 14 | } else { |
| 15 | $input_values = $value; |
| 16 | } |
| 17 | ?> |
| 18 | <div class="clone-element-container"> |
| 19 | <?php |
| 20 | foreach ($input_values as $text_value) { |
| 21 | ?> |
| 22 | <?php |
| 23 | if (!\in_array($field->get_type(), ['number', 'text', 'hidden'], \true)) { |
| 24 | ?> |
| 25 | <input type="hidden" name="<?php |
| 26 | echo \esc_attr($name_prefix) . '[' . \esc_attr($field->get_name()) . ']'; |
| 27 | ?>" value="no"/> |
| 28 | <?php |
| 29 | } |
| 30 | ?> |
| 31 | |
| 32 | <?php |
| 33 | if ($field->get_type() === 'checkbox' && $field->has_sublabel()) { |
| 34 | ?> |
| 35 | <label><?php |
| 36 | } |
| 37 | ?> |
| 38 | <div class="clone-wrapper"> |
| 39 | <input |
| 40 | type="<?php |
| 41 | echo \esc_attr($field->get_type()); |
| 42 | ?>" |
| 43 | name="<?php |
| 44 | echo \esc_attr($name_prefix) . '[' . \esc_attr($field->get_name()) . '][]'; |
| 45 | ?>" |
| 46 | id="<?php |
| 47 | echo \esc_attr($field->get_id()); |
| 48 | ?>" |
| 49 | |
| 50 | <?php |
| 51 | if ($field->has_classes()) { |
| 52 | ?> |
| 53 | class="<?php |
| 54 | echo \esc_attr($field->get_classes()); |
| 55 | ?>" |
| 56 | <?php |
| 57 | } |
| 58 | ?> |
| 59 | |
| 60 | <?php |
| 61 | if ($field->get_type() === 'text' && $field->has_placeholder()) { |
| 62 | ?> |
| 63 | placeholder="<?php |
| 64 | echo \esc_html($field->get_placeholder()); |
| 65 | ?>" |
| 66 | <?php |
| 67 | } |
| 68 | ?> |
| 69 | |
| 70 | <?php |
| 71 | foreach ($field->get_attributes() as $key => $atr_val) { |
| 72 | echo \esc_attr($key) . '="' . \esc_attr($atr_val) . '"'; |
| 73 | ?> |
| 74 | <?php |
| 75 | } |
| 76 | ?> |
| 77 | |
| 78 | <?php |
| 79 | if ($field->is_required()) { |
| 80 | ?> |
| 81 | required="required"<?php |
| 82 | } |
| 83 | ?> |
| 84 | <?php |
| 85 | if ($field->is_disabled()) { |
| 86 | ?> |
| 87 | disabled="disabled"<?php |
| 88 | } |
| 89 | ?> |
| 90 | <?php |
| 91 | if ($field->is_readonly()) { |
| 92 | ?> |
| 93 | readonly="readonly"<?php |
| 94 | } |
| 95 | ?> |
| 96 | <?php |
| 97 | if (\in_array($field->get_type(), ['number', 'text', 'hidden'], \true)) { |
| 98 | ?> |
| 99 | value="<?php |
| 100 | echo \esc_html($text_value); |
| 101 | ?>" |
| 102 | <?php |
| 103 | } else { |
| 104 | ?> |
| 105 | value="yes" |
| 106 | <?php |
| 107 | if ($value === 'yes') { |
| 108 | ?> |
| 109 | checked="checked" |
| 110 | <?php |
| 111 | } |
| 112 | ?> |
| 113 | <?php |
| 114 | } |
| 115 | ?> |
| 116 | /> |
| 117 | <span class="add-field"><span class="dashicons dashicons-plus-alt"></span></span> |
| 118 | <span class="remove-field hidden"><span class="dashicons dashicons-remove"></span></span> |
| 119 | </div> |
| 120 | |
| 121 | <?php |
| 122 | if ($field->get_type() === 'checkbox' && $field->has_sublabel()) { |
| 123 | ?> |
| 124 | <?php |
| 125 | echo \esc_html($field->get_sublabel()); |
| 126 | ?></label> |
| 127 | <?php |
| 128 | } |
| 129 | } |
| 130 | ?> |
| 131 | </div> |
| 132 | <style> |
| 133 | .clone-element-container .clone-wrapper .add-field { |
| 134 | display: none; |
| 135 | } |
| 136 | .clone-element-container .clone-wrapper:first-child .add-field { |
| 137 | display: inline-block; |
| 138 | } |
| 139 | |
| 140 | .clone-element-container .clone-wrapper .remove-field { |
| 141 | display: inline-block; |
| 142 | } |
| 143 | .clone-element-container .clone-wrapper:first-child .remove-field { |
| 144 | display: none; |
| 145 | } |
| 146 | </style> |
| 147 | <script> |
| 148 | jQuery( function ( $ ) { |
| 149 | var add_field = jQuery( '.add-field' ); |
| 150 | if ( add_field.length ) { |
| 151 | add_field.click( function ( e ) { |
| 152 | let html = jQuery( this ).closest( '.clone-wrapper' ).clone(); |
| 153 | html.find( 'input' ).val( '' ); |
| 154 | jQuery( this ).closest( '.clone-wrapper' ).after( html ); |
| 155 | } ) |
| 156 | |
| 157 | jQuery( '.clone-element-container' ).on( "click", ".remove-field", function ( e ) { |
| 158 | let is_disabled = jQuery( this ).hasClass( 'field-disabled' ); |
| 159 | if ( !is_disabled ) { |
| 160 | jQuery( this ).closest( '.clone-wrapper' ).remove(); |
| 161 | } |
| 162 | } ) |
| 163 | |
| 164 | jQuery( '.form-table' ).find( 'input,select' ).each( function ( i, v ) { |
| 165 | let disabled = jQuery( this ).attr( 'data-disabled' ); |
| 166 | if ( disabled === 'yes' ) { |
| 167 | jQuery( this ).attr( 'disabled', 'disabled' ) |
| 168 | jQuery( this ).parent().addClass( 'field-disabled' ); |
| 169 | } |
| 170 | } ); |
| 171 | } |
| 172 | } ); |
| 173 | </script> |
| 174 | <?php |
| 175 |