Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Form Validation: Required Value for Select Box with Default Option

Started by Muut Archive 9 years ago · 4 replies · 743 views
9 years ago

I'm in the process of building a form in Grav, and I have a select box of Canadian provinces. I want to make sure that the user is specifying their province, so I have a default placeholder "default: Select Your Province". How do I validate this field so that it is required but the placeholder value isn't accepted as valid?

9 years ago

Here's what I have at the moment:
---yaml

name: province
id: province
label: Province
type: select
options:
default: Select Your Province
AB: Alberta
BC: British Columbia
MB: Manitoba
NB: New Brunswick
NL: Newfoundland and Labrador
NT: Northwest Territories
NS: Nova Scotia
NU: Nunavut
ON: Ontario
PE: Prince Edward Island
QC: Quebec
SK: Saskatchewan
YT: Yukon
validate:
required: true

9 years ago

Instead of a default value, you can use placeholder instead!

YAML

name: province
id: province
placeholder: Select your Province
label: Province
type: select

9 years ago

I can't believe I didn't think of that, seeing as I was already using placeholders for my other fields. Thanks!

9 years ago

Also please update to latest Form plugin, there has been a couple of fixes that might affect this.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1333 9 years ago
Archive · by Muut Archive, 9 years ago
2 924 9 years ago
Archive · by Muut Archive, 9 years ago
2 4055 9 years ago
Archive · by Muut Archive, 9 years ago
1 2933 9 years ago
Archive · by Muut Archive, 9 years ago
3 1110 9 years ago