Topic: Change Input Validation To False

robertsi77 free asked 1 year ago


I have radio buttons that depending the selected option, some inputs or selects should be either required or not. Once created all of them are required, but if the "No Required" option is selected, some of them need to change no not being required.

I tried by catching the On change action of the radio button, and changing the attribute by jQuery just like this:

$("#basic-select").attr('data-mdb-validation', false);

and the attribute changes, but when clicking Submit in the form, the input keeps telling me it is required to fill.

How can I do my expected behavior?


Michał Duszak staff answered 1 year ago


There is not such method - but you can dispose the select element and initialize a new one without validation attribute, here is an example snippet: https://mdbootstrap.com/snippets/standard/m-duszak/3924363#js-tab-view


robertsi77 free commented 1 year ago

I tried your solution and worked as you mentioned, but the problem now is that the inputs and Selects I am using, use a label. So, every time I initialize them as new, the label disappears.

I modified your snippet and added a Label: https://mdbootstrap.com/snippets/standard/robertsi77/3925372


Michał Duszak staff commented 1 year ago

Hello, does your snippet resolve the issue?


robertsi77 free commented 1 year ago

No, it did not resolve it. As I mentioned, when you have a label in the input and initialize it again (as you did in your snippet), the label disappears. So, I just added a Label in my snippet, for you to see that.


Michał Duszak staff commented 1 year ago

But in your snippet, the label gets changed to the label of your choice - in this example its "label no required" and "label required". I understand that this is the case.



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Opened

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: MDB5 4.0.0
  • Device: Macbook Air
  • Browser: Chrome
  • OS: MacOS
  • Provided sample code: No
  • Provided link: No