Radio button, without pre-selection?

WordPress Event Management, Calendars & Registration Forums General Question Radio button, without pre-selection?

This topic contains 2 replies, has 2 voices, and was last updated by  AK 5 years, 5 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #32087

    Hi,

    We need to create a yes/no question where there can´t be any option selected default.
    From what I can tell it´s not possible to create radiobuttons without a pre-selected option with Even Organiser?

    Thanks!

    AK
    #32124

    Not via the form customiser. You can add the field via the API and not set the ‘selected’ property or you could get the radio element you’ve added (ID 23 in the example below) and unset the selected property:

    <?php

     add_action( 'eventorganiser_get_event_booking_form', 'add_field_to_booking_form', 10, 2 );
     function add_field_to_booking_form( $form, $event_id ){
         $radio = EO_Booking_Form_Element_Factory::create( array(
             'type'        => 'radio',
             'id'          => 'my-unique-id', //Must be unique in the form. You should not use 'name', 'ticketpicker', 'gateway' or 'email' as an ID,
             'label'       => 'Select an option:',
             'options'     => array( 'A' => 'Option A', 'B' => 'Option B', 'C' => 'Option C' ),
             'required'    => true, //Default is false
             'description' => "Pick one of the options",
         ) );
    
         $form->add_element( $radio );
     }
    
     add_action( 'eventorganiser_get_event_booking_form', 'add_edit_field_booking_form', 10, 2 );
     function add_edit_field_booking_form( $form, $event_id ){
         $element = $form->get_element( 23 );
         $element->set( 'selected', null ); 
     }
    
    Stephen Harris
    #32144

    Perfect, thank you!

    AK
Viewing 3 posts - 1 through 3 (of 3 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.