question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I Validate Input Type Select

See original GitHub issue

Suppose I have a below select element: <AvField type="select" id="SalaryType" name="SalaryType" helpMessage="" required > <option>Select Frequency of Salary</option> <option value="1">Monthly</option> <option value="2">Bi-Weekly</option> <option value="3">Weekly</option> <option value="4">Fortnightly</option> </AvField>

Is there a option to show error when selected option is ‘Select Frequency of Salary’?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
TheSharpieOnecommented, Mar 27, 2018

If no value is set on an <option> it will default to the text with in the <option> (this is per the HTML spec and is handled by the browser). So, the first option ends up having the value of Select Frequency of Salary, which is not empty so it passes the required validation. If you add value="" to the option, it should work as you intended. Demo: https://stackblitz.com/edit/reactstrap-validation-v2-zk6fkc?file=Example.js

Also, since the default value is will be "" (after the change mentioned above), it will not show the error initially. If the user changes the value and then changes it back, it should show the error. Additional, it the user doesn’t change the value and tries to submit the form, it should show the error.

1reaction
TheSharpieOnecommented, Mar 28, 2018

Take a look at #19

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validate select box - javascript - Stack Overflow
select = document.getElementById('select'); // or in jQuery use: select = this; if (select.value) ...
Read more >
Validate (Check) HTML Select DropDownList using JavaScript ...
Here Mudassar Ahmed Khan has explained how to validate (check) HTML Select DropDownList using JavaScript and jQuery. ; select id="ddlFruits"> ; select> ;...
Read more >
HTML select required Attribute - W3Schools
The required attribute is a boolean attribute. When present, it specifies the user is required to select a value before submitting the form....
Read more >
Form Validation - Tom Select
User input validation in Tom Select is built on standard validation protocols introduced by HTML5. As a user changes the items of a...
Read more >
Validation · Bootstrap v5.0
HTML form validation is applied via CSS's two pseudo-classes, :invalid and :valid . It applies to <input> , <select> , and <textarea> elements....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found