How to handle interdependencies
See original GitHub issueA missing feature is to handle interdependent fields better.
I’m trying to see how we would group those, and maybe something as simple as data-parsley-multiple="some-unique-name"
would be good enough.
Here’s what I’m thinking would be a good way to write a custom validator for a date written in three separate fields (we could start from there for an extra/
validator). Each also has individual validator, although that’s more for show than anything else and I’m not sure it’s worth implementing?
Parsley.addValidator('date', {
requirementKind: {
'': 'string', // Can be 'past', 'future', or nothing
dmyPosition: ['integer', 'integer', 'integer'] // Defaults to 0, 1, 2, i.e. day then month then year
},
validateMultiple: function(values, kind, options) {
// Adapted from http://stackoverflow.com/a/8098359/8279
var position = options.dmyPosition || [0, 1, 2];
var day = parseInt(values[position[0]], 10);
var month = parseInt(values[position[1]], 10) - 1; // Month is 0 based...
var year = parseInt(values[position[2]], 10);
var date = new Date(year, month, day);
if (date.getFullYear() != year ||
date.getMonth() != month ||
date.getDate() == date)
return false;
switch(kind) {
case 'past': return date < new Date();
case 'future': return date >= new Date();
}
return true;
}
})
<div class="input-date">
Please enter your date of birth:
<label>Year:
<input data-parsley-date="past" data-parsley-date-dmy-position="[2,1,0]" data-parsley-multiple="dob" name="year" type="number" required data-parsley-range="[1900,2015]">
<label>Month:
<input data-parsley-multiple="dob" name="month" type="number" required data-parsley-range="[1, 12]">
<label>
<label>Day:
<input data-parsley-multiple="dob" name="day" type="number" required data-parsley-range="[1, 31]"></label>
</label>
</div>
@guillaumepotier what do you think about this?
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to Manage Project Dependencies and Interdependencies
On this project interdependency mapping is complete, the next step is to get the whole team together and hold a Dependency Culling Workshop....
Read more >Project interdependency management - PMI
This process results in an approved set of project interdependencies that includes a detailed description of each interdependency and a risk rating based...
Read more >How to Manage Interdependencies in a Project Portfolio
Consider if we made investment decisions based purely on value - with no other considerations. Without factoring for the interdependencies in ...
Read more >What Project Interdependencies Span Your Portfolio? - Saviom
4. How to Manage Project Dependencies? · Step 1: Identify all Project Dependencies · Step 2: Hold a Dependency Workshop · Step 3:...
Read more >3 wildly effective strategies to manage project dependencies
Focus your efforts on restructuring the projects or their tasks and redistributing them, so there are as few involved parties in a single...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What about using some PHP-like syntax:
validator#role[]
and then passingvalues = {role: [ … ]}
to the validator?Have you an example use-case for that? I find it hard to theorise about that without one ^^. I guess some implicit grouping of checkboxes / radios with the same name-attribute might be good.
Reading thru the factory.js file - it appears the data attribute namespace-multiple has no influence on if an input field is a multiple or not. Am I correct in assuming that the multiple data attribute is only for grouping elements that are already a multi field (radio, checkbox, select[multiple]).