question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to handle interdependencies

See original GitHub issue

A 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:open
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
torotilcommented, Sep 10, 2015

Do we need to support variable number of fields in the group (in which case naming them might be tedious)?

What about using some PHP-like syntax: validator#role[] and then passing values = {role: [ … ]} to the validator?

Other open questions: groups of checkboxes & radios should be treated differently or not?

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.

0reactions
edmeehan-tcgcommented, Jul 8, 2016

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]).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found