Radio field ignores 'std' parameter when used in conjunction with other fields

Support General Radio field ignores 'std' parameter when used in conjunction with other fieldsResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #38837
    RJ LaanRJ Laan
    Participant

    Hi!

    I am using a radio button field and what to set a default value.

    This is the definition:

    [
    	'name'    => 'Circuit type',
    	'id'      => "{$prefix}circuit_type",
    	'type'    => 'radio',
    	'inline'  => true,
    	'options' => [
    		'regular'     => 'Regular',
    		'maintenance' => 'Maintenance',
    	],
    	'std'     => 'regular',
    ],

    My problem is, this only works if the field is on it's own. The moment I add another field to the fields array it no longer works.

    This confuses me a lot so I hope you can help me.

    Thanks,
    Ruud

    #38838
    RJ LaanRJ Laan
    Participant

    I figured it out myself: the 'std' value won't work if any of the other fields in the same definition have already been saved to the database.
    I know I have read about this but thought it meant that this particular field must not be saved already, which would make total sense since it would then have a saved value already.

    Why can't it work if the field itself has not been saved to the db?

    #38847
    Long NguyenLong Nguyen
    Moderator

    Hi,

    We've created a note about this case in the documentation, please read more here https://docs.metabox.io/creating-fields-with-code/#why-does-not-my-default-value-work

    #38854
    RJ LaanRJ Laan
    Participant

    Hi Long,

    Thanks for the reply and the FAQ is very helpful too!

    If I may comment on the phrasing of the FAQ question (please do not feel offended, just trying to help);
    I believe that "Why is my default value not working?" is a better way of writing the question.

    Thanks,
    Ruud

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.