javascript - How to switch error Messages in Parsley.js -
i have written specific validator parsley.js determine if selected date matches criteria:
- date between , b years in past.
- if min-date given, there should message
i have solved writing 1 function , assign 2 validators able translate messages differently.
is there better way dynamically switch message based on parameters given validator?
// translationkeys: // timerange: "muss zwischen %s und %s jahren in der vergangenheit liegen" // mintimerage: "muss mindestens %s jahr(e) in der vergangenheit liegen" var timevalidator = function (value, req) { if(req.min){ var mindate = moment().subtract(req.min, 'y'); } if(req.max){ var maxdate = moment().subtract(req.max, 'y'); } var date = moment(value, 'dd.mm.yyyy'); if( req.max ){ return ( date.isafter(maxdate)&& date.isbefore(mindate) ); } else { return ( date.isbefore(mindate) ); } } window.parsleyvalidator.addvalidator('timerange', timevalidator, 32 ) window.parsleyvalidator.addvalidator('mintimerange', timevalidator, 32 )
solved: there no possibility.
Comments
Post a Comment