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

Required fields #104

Open
danielbachhuber opened this issue Mar 10, 2014 · 7 comments
Open

Required fields #104

danielbachhuber opened this issue Mar 10, 2014 · 7 comments
Labels
enhancement New feature or request
Milestone

Comments

@danielbachhuber
Copy link
Contributor

How do you feel about adding the ability to mark certain fields as "required" (however you might define that)?

@bcampeau
Copy link
Member

We've already integrated jQuery Validation and you can see the general description of how it works in the comments here: https://github.com/alleyinteractive/wordpress-fieldmanager/blob/master/php/class-fieldmanager-field.php#L131-L153

@danielbachhuber danielbachhuber added this to the later milestone Mar 13, 2014
@macedd
Copy link

macedd commented Jul 3, 2014

I think a working example in the demo would fit well for this feature.

@netaustin
Copy link
Contributor

I think ultimately we should be able to PHP-require some fields and allow custom validation callbacks.

@netaustin netaustin reopened this Sep 20, 2014
@montchr
Copy link
Contributor

montchr commented Oct 20, 2015

I'd also appreciate a working example of this.

@mboynes mboynes added enhancement New feature or request and removed enhancement New feature or request labels Feb 19, 2016
@simonrcodrington
Copy link

I'd appreciate a working example of this also. The documentation here isn't very helpful: http://api.fieldmanager.org/class-Fieldmanager_Field.html#$validation_rules

I assumed I'd be able to do something similar and the jquery validation would handle the rest

'validation_rules' => ['required' => true], 'validation_messages' => ['required' => 'its required sorry']

This doesn't seem to work and there's not really much documentation as to the format / how this should work.

@bjorn2404
Copy link

Came looking for an example but then found in the Fieldmanager_Field class that you want to pass it in as an attribute, which will add the HTML5 required attribute to the field. If it helps, there's an example at http://api.fieldmanager.org/class-Fieldmanager_Field.html#$attributes

@montchr
Copy link
Contributor

montchr commented Jul 11, 2018

I assumed I'd be able to do something similar and the jquery validation would handle the rest

'validation_rules' => ['required' => true], 'validation_messages' => ['required' => 'its required sorry']

This doesn't seem to work and there's not really much documentation as to the format / how this should work.

I tried the same approach and it ended up working out:

'url' => new \Fieldmanager_Link( 'Destination URL', [
    'description'         => 'All messages are linked to a destination page',
    'validation_rules'    => [
        'required' => true,
        'url'      => true,
    ],
    'validation_messages' => [
        'required' => 'Required',
        'url'      => 'This is not a URL!',
    ],
    'attributes' => [
        'placeholder' => 'https://',
    ],
] ),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants