base.html.php
4 years ago
checkbox.html.php
4 years ago
file.html.php
4 years ago
hidden.html.php
4 years ago
html.html.php
4 years ago
label-content.html.php
4 years ago
label.html.php
4 years ago
radio.html.php
4 years ago
select.html.php
4 years ago
textarea.html.php
4 years ago
select.html.php
42 lines
| 1 | <?php /** @var Give\Framework\FieldsAPI\Select $field */ ?> |
| 2 | <?php /** @var string $fieldIdAttribute */ ?> |
| 3 | <select |
| 4 | name="<?php echo $field->getName(); ?><?php echo $field->getAllowMultiple() ? '[]' : ''; ?>" |
| 5 | id="<?php echo $fieldIdAttribute; ?>" |
| 6 | <?php echo $field->getAllowMultiple() ? 'multiple' : ''; ?> |
| 7 | <?php echo $field->isRequired() ? 'required' : ''; ?> |
| 8 | <?php echo $field->isReadOnly() ? 'readonly' : ''; ?> |
| 9 | <?php |
| 10 | if ( $conditions = $field->getVisibilityConditions() ) { |
| 11 | $conditions = esc_attr( json_encode( $conditions ) ); |
| 12 | echo "data-field-visibility-conditions=\"$conditions\""; |
| 13 | } |
| 14 | ?> |
| 15 | > |
| 16 | <?php |
| 17 | if ( $placeholder = $field->getPlaceholder() ) { |
| 18 | printf( |
| 19 | '<option value="" %2$s %3$s>%1$s</option>', |
| 20 | $placeholder, |
| 21 | $field->isRequired() ? 'disabled' : '', |
| 22 | $field->getDefaultValue() ? '' : 'selected' |
| 23 | ); |
| 24 | } |
| 25 | ?> |
| 26 | <?php foreach ( $field->getOptions() as $option ) : ?> |
| 27 | <?php |
| 28 | $value = esc_attr( $option->getValue() ); |
| 29 | $label = $option->getLabel(); |
| 30 | $default = $field->getAllowMultiple() ? |
| 31 | in_array( $option->getValue(),$field->getDefaultValue() ) : |
| 32 | $field->getDefaultValue() === $option->getValue(); |
| 33 | ?> |
| 34 | <option |
| 35 | <?php echo $label ? "value=\"$value\"" : ''; ?> |
| 36 | <?php echo $default ? 'selected' : ''; ?> |
| 37 | > |
| 38 | <?php echo $label ?: $value; ?> |
| 39 | </option> |
| 40 | <?php endforeach; ?> |
| 41 | </select> |
| 42 |