• Resolved Salih K

    (@salihkulangara)


    I am using PMPRO with Register Helper add on, I have created a conditional field like this:

    $fields[] = new PMProRH_Field(
        'profession',
        'radio', // type of field
        	array(
            'options' =>
                array(
                    'Judge' => 'Judge',
                    'Attorney' => 'Attorney',
                    'Social Worker' => 'Social Worker',
                    'Attorney & Social Worker' => 'Attorney & Social Worker',
                    'Other' => 'Other'
                ),
            'label'=>'Profession',
            'required'=>true,
    	'profile'	=> true,
      	)
        );
    	$fields[] = new PMProRH_Field(
                "other_profession",
                 "textarea",
                  array(
    		"depends"=>array(array('id' => "profession", 'value' => "Other")),
    		"label"=>"Please Specify Other",
    		'profile'	=> true,
            ));
    

    so I need the dependent field(please specify other field) required only if the “other” option selected from the “Profession”. If I give ‘required’=>true to “other_profession”(Please Specify Other) this dependent field will be always be required, and even if I don’t select other option from “Profession” I get required field error when submit the form. Is there any option I am missing, or any work around?

    • This topic was modified 5 years, 10 months ago by Salih K.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Andrew Lima

    (@andrewza)

    Hi @salihkulangara,

    Thank you for using Paid Memberships Pro.

    Please can you set the depends field to be optional. We are aware of this issue and will look into fixing this in the near future.

    You could write some JavaScript to make the field required if it’s displaying.

    I’m sorry for the inconvenience caused by this.

    Thread Starter Salih K

    (@salihkulangara)

    Thank you for your quick response.

    Thread Starter Salih K

    (@salihkulangara)

    Hi,

    You could write some JavaScript to make the field required if it’s displaying.

    could you please give me a hint? how could we make a field required using js, because I could not see any special classes/atts added to required fields.

    thanks in advance

    Plugin Author Andrew Lima

    (@andrewza)

    You could add the HTML attribute “required” when showing the field with jQuery. You can remove the “Depends” code inside your custom fields and then write your own custom JavaScript to show/hide the field depending on the field selected.

    Here’s an example you may work from – https://gist.github.com/andrewlimaza/6c3ca0320cf318b5c58bf866e0fab3f5

    Thread Starter Salih K

    (@salihkulangara)

    Thank you so much

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Conditional Fields and Required attribute not working as intended’ is closed to new replies.