Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p-dropdown support for HTML5 required attribute #230

Closed
gatapia opened this issue Apr 20, 2016 · 3 comments
Closed

p-dropdown support for HTML5 required attribute #230

gatapia opened this issue Apr 20, 2016 · 3 comments
Assignees
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Milestone

Comments

@gatapia
Copy link
Contributor

gatapia commented Apr 20, 2016

Currently 'requred' attribute is ignored on p-dropdown. It would be good if this was supported. Currently I have hacked this as follows:

# template
<p-dropdown [options]="list" [(ngModel)]="listid"></p-dropdown>
<input class='hidden-validator' type="number" [(ngModel)]="listid" required>

# component
listid;
list = [{value: '', label: 'Select...'}, {value: 1, label: '1'}];

# css
 /* 
hide it behind the dropdown component, the required 
  HTML5 pop up still shows which is good and the form
 is still marked as not valid 
*/
.hidden-validator {
  position: absolute;
  left: 600px;
  z-index: -1; 
}
@cghislai
Copy link

You can already use the required attribute on p-dropdown, although without the browser popup (which I assume is only displayed for HTML <input><select><textarea> components):

                    <p-dropdown ngControl="test"
                                #testControl="ngForm"
                                [options]="testOptions"
                                [(ngModel)]="testValue"
                                required>

                    </p-dropdown>
                    <div [hidden]="testControl.control?.status !== 'INVALID' ">
                      Value is required
                    </div>

@cagataycivici
Copy link
Member

We have a hidden select tag inside, I'll add required to it.

@cagataycivici cagataycivici added the Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add label Apr 26, 2016
@cagataycivici cagataycivici added this to the 1.0.0-beta.4 milestone Apr 26, 2016
@cagataycivici cagataycivici self-assigned this Apr 26, 2016
@gatapia
Copy link
Contributor Author

gatapia commented May 2, 2016

Thanks for this. Just a note for others: this requires that required="true" be set. requred on its own does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Projects
None yet
Development

No branches or pull requests

3 participants