Jump to content


Changing required fields based on Dropdown

required fields dropdown

  • Please log in to reply
2 replies to this topic

#1 Berk

Berk

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 25 February 2016 - 02:19 PM

Hi,

 

I want to be able to change which fields are required based on result from a dropdown. Ex: if result is A, I want B and C to be required. Else if result is B, I want only C to be required. 

Is there a way to change required fields on the fly?

 

Thanks

Berk

 



#2 titu

titu

    Advanced Member

  • Members
  • PipPipPip
  • 43 posts

Posted 26 February 2016 - 04:07 PM

You could hard code somehting in javascript.



#3 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 28 February 2016 - 06:57 PM

Well that is 1 way - there is another way around - i am sharing you 1 of the example...

 

        $state_required_if = $this->input->post('other_state') ? '' : '|required';
        $crud->set_rules('state', 'State / Province', 'trim' . $state_required_if);
 

well.. here if you see . what i am doing is - if the drop down value selected is other_state - it will ignore state .. else it will ensure it is set required.

Every time the validation needs to be done - GC makes an ajax call .. where it sees this condition - dynamically generated.

 

You can alter the same accordingly to your needs.

 

Happy GCing. 







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users