0

I have the following code:

<select id="document" ng-model="document.Id" ng-options="option.Id as option.Name for option in documents" ng-required="IsDocumentRequired">
    <option value="">Please Select Document</option>
</select>

The issue is that I don't want this default value ("Please select Document"), to satisfy the ng-required flag when it is set to true.

In summary, I want the user to be forced to choose an option other than the default.

Thanks

3
  • 1
    Is this not working now? The value="" <option> should make that option not satisfy the ng-required already.
    – zero298
    Jul 26, 2016 at 14:17
  • @bboyk see the plunker demo Jul 26, 2016 at 14:29
  • Just use required. There's no requirements to use ng-required here. Jul 27, 2016 at 2:29

3 Answers 3

2

When your value is "" it does not satisfy ng-required for select, select's required field validation passes only when select option is not equal to empty, It is designed that way

See the plunker demo, https://plnkr.co/edit/tfeXhHY3h98ItX322JVS?p=preview

0

Do not use the

<option value="">Please Select Document</option>

So it wont display it and user should select one item from the list

1
  • Thanks, however I need placeholder text in the select box
    – bak
    Jul 26, 2016 at 14:20
0

You can test the selected value (in your case, I recommend you to put "-1" as value of "Please Select Document").

If the user do not select another value, treat it as an error.

Or see the response in How do I make a placeholder for a 'select' box?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.