Support

Account

Home Forums Front-end Issues Fontend form radio button default to none

Solving

Fontend form radio button default to none

  • I have a radio button field with 2 options, yes and no. When displaying this field on a frontend form the radio buttons default to the first option, yes. I need none of the radio buttons to be selected until the user makes a choice.

    I have tried spaces and non existent values in the default value field but this doesn’t help.

    Thanks

  • Same issue here. No matter what I try it is defaulting to the first value, which is obviously not what should happen.

  • Just bought this plugin yesterday. I found out that issue today but i think i have solved it.

    1) Go to advanced-custom-fields-pro/fields/radio.php and than line 138

    2) Change line 138 to:
    if( strval($value) === strval($field[‘default_value’]) ) {

    Hope to help you guys.
    Sorry, thats not the right answer yet. I’m trying to find out yet that causes that bug

  • How is this not something being addressed by the developer??

  • I really need that working.

    I’m still trying to find in which part of the code that bug is coming from. But of course I would prefer that a ACF developer had solving that

  • Hi,

    Any news of this bug?

    I need radio button default to none because in my page is used as conditional, and conditional has required field…

  • If this is for a frontend form, I would create a third option for a default null value, and then remove the third radio button with js. Not ideal, but a workaround until this is addressed.

  • Same issue. I have two options for the radio button and they are conditional. Meaning if the user chooses one it shows one field if the user chooses the other it should show a different field.

    It defaults to the first radio button but doesn’t show the conditional field so the user would have to toggle to the other option and then back to the original one. Very surprised such a bug hasn’t been addressed yet.

    One temporary fix is entering the word null into the the default value field which resolves the issue but it’s a radio button so should be empty by default. So worried that after I enter in these 400 entries there may be an update that may break compatibility with the null hack.

  • The validation happens on the front-end, so if you remove the third option via js, then the value of that field will be blank and therefore will not allow the user to pass validation.

    I’ve removed and added options after-the-fact before and that has never changed the values of the other entries.

  • another option would be to use a select field rather than radio buttons

  • As I mentioned above you can simply set the default value to “null” and that way no value will be selected by default. And you don’t need to remove “null” via javascript as it won’t show on the frontend at all by default. Just make sure you add “null” to the default value field and not in the list of other normal values.

    However, the radio button defaulting to the first field still appears to a bug that should be addressed by ACF.

  • in fields/radio.php I’m seeing this bit of code at line 114-119

    			// select first choice if value is not a valid choice
    			if( !isset($field['choices'][ $field['value'] ]) ) {
    				
    				$field['value'] = key($field['choices']);
    				
    			}

    This seems to be where the first option is set by default – can anyone tell me why there might be a good reason to NOT delete these lines (other than editing core plugin files). What purpose does this bit of code have?

  • @cchiera i tried what you said and it still selects the first radio button by default.

  • yes the null trick didn’t work for me either

  • Seeing this issue as well (ACF 5.2.5). Changing the field to a ‘select’ until fixed.

  • I work around this issue all the time, and I’m wondering what can be done to get it elevated to a status in which it’s addressed (this thread is now 10 months old). Can we please have radio buttons that have no default selection, with the ability to set default selection if desired?

  • This is an old thread now, but I found it whilst looking to figure out a similar problem, so for anyone who does the same here’s how I managed it.

    In version 5.3.8 the option to ‘allow null’ was added to the radio button field settings. If you allow this, then make sure the ‘default’ field is empty, nothing is selected on load.

  • After 4 years, the lack of an official response to this thread is very disappointing.

    Really don’t understand WHY it would default to a value with you giving it one.

Viewing 19 posts - 1 through 19 (of 19 total)

The topic ‘Fontend form radio button default to none’ is closed to new replies.