pro
1 year ago
_acf-compatibility.js
1 year ago
_acf-condition-types.js
1 year ago
_acf-condition.js
1 year ago
_acf-conditions.js
1 year ago
_acf-field-accordion.js
1 year ago
_acf-field-button-group.js
1 year ago
_acf-field-checkbox.js
1 year ago
_acf-field-color-picker.js
1 year ago
_acf-field-date-picker.js
1 year ago
_acf-field-date-time-picker.js
1 year ago
_acf-field-file.js
1 year ago
_acf-field-google-map.js
1 year ago
_acf-field-icon-picker.js
1 year ago
_acf-field-image.js
1 year ago
_acf-field-link.js
1 year ago
_acf-field-oembed.js
1 year ago
_acf-field-page-link.js
1 year ago
_acf-field-post-object.js
1 year ago
_acf-field-radio.js
1 year ago
_acf-field-range.js
1 year ago
_acf-field-relationship.js
1 year ago
_acf-field-select.js
1 year ago
_acf-field-tab.js
1 year ago
_acf-field-taxonomy.js
1 year ago
_acf-field-time-picker.js
1 year ago
_acf-field-true-false.js
1 year ago
_acf-field-url.js
1 year ago
_acf-field-user.js
1 year ago
_acf-field-wysiwyg.js
1 year ago
_acf-field.js
1 year ago
_acf-fields.js
1 year ago
_acf-helpers.js
1 year ago
_acf-hooks.js
1 year ago
_acf-internal-post-type.js
1 year ago
_acf-media.js
1 year ago
_acf-modal.js
1 year ago
_acf-model.js
1 year ago
_acf-notice.js
1 year ago
_acf-panel.js
1 year ago
_acf-popup.js
1 year ago
_acf-postbox.js
1 year ago
_acf-screen.js
1 year ago
_acf-select2.js
1 year ago
_acf-tinymce.js
1 year ago
_acf-tooltip.js
1 year ago
_acf-unload.js
1 year ago
_acf-validation.js
1 year ago
_acf.js
1 year ago
_browse-fields-modal.js
1 year ago
_field-group-compatibility.js
1 year ago
_field-group-conditions.js
1 year ago
_field-group-field.js
1 year ago
_field-group-fields.js
1 year ago
_field-group-locations.js
1 year ago
_field-group-settings.js
1 year ago
_field-group.js
1 year ago
acf-escaped-html-notice.js
1 year ago
acf-field-group.js
1 year ago
acf-input.js
1 year ago
acf-internal-post-type.js
1 year ago
acf.js
1 year ago
_acf-field-radio.js
64 lines
| 1 | ( function ( $, undefined ) { |
| 2 | var Field = acf.Field.extend( { |
| 3 | type: 'radio', |
| 4 | |
| 5 | events: { |
| 6 | 'click input[type="radio"]': 'onClick', |
| 7 | }, |
| 8 | |
| 9 | $control: function () { |
| 10 | return this.$( '.acf-radio-list' ); |
| 11 | }, |
| 12 | |
| 13 | $input: function () { |
| 14 | return this.$( 'input:checked' ); |
| 15 | }, |
| 16 | |
| 17 | $inputText: function () { |
| 18 | return this.$( 'input[type="text"]' ); |
| 19 | }, |
| 20 | |
| 21 | getValue: function () { |
| 22 | var val = this.$input().val(); |
| 23 | if ( val === 'other' && this.get( 'other_choice' ) ) { |
| 24 | val = this.$inputText().val(); |
| 25 | } |
| 26 | return val; |
| 27 | }, |
| 28 | |
| 29 | onClick: function ( e, $el ) { |
| 30 | // vars |
| 31 | var $label = $el.parent( 'label' ); |
| 32 | var selected = $label.hasClass( 'selected' ); |
| 33 | var val = $el.val(); |
| 34 | |
| 35 | // remove previous selected |
| 36 | this.$( '.selected' ).removeClass( 'selected' ); |
| 37 | |
| 38 | // add active class |
| 39 | $label.addClass( 'selected' ); |
| 40 | |
| 41 | // allow null |
| 42 | if ( this.get( 'allow_null' ) && selected ) { |
| 43 | $label.removeClass( 'selected' ); |
| 44 | $el.prop( 'checked', false ).trigger( 'change' ); |
| 45 | val = false; |
| 46 | } |
| 47 | |
| 48 | // other |
| 49 | if ( this.get( 'other_choice' ) ) { |
| 50 | // enable |
| 51 | if ( val === 'other' ) { |
| 52 | this.$inputText().prop( 'disabled', false ); |
| 53 | |
| 54 | // disable |
| 55 | } else { |
| 56 | this.$inputText().prop( 'disabled', true ); |
| 57 | } |
| 58 | } |
| 59 | }, |
| 60 | } ); |
| 61 | |
| 62 | acf.registerFieldType( Field ); |
| 63 | } )( jQuery ); |
| 64 |