Comments (9)
In short, for list of of forms .check
prop is strictly boolean, it governs whether errors in subforms are reflected to this.my.errors()
and this.my.valid()
. So if .check
in list declaration is boolean and subform(s) has errors, calling this.my.errors()
returns smth like {'#list':{15:{'#someCtrl':'Some error'}}}
where 15 is zero-based index of the subform with error.
If you want to check overall list health (some meta-conditions, like no identical elts, or odd number of entries required etc) you better follow common practice for this sort of tasks:
- you make a proxy div somewhere, it may be hidden or reflect some useful info about list state, ie elt counter or sort of stats
- that proxy div has own ui section and
.watch:['#listToFollow']
inside, so it checks on list changed - div’s bind function contains all logic to check list health and, optionally, to output a message
- also that proxy might have say
.delay:500
not to be called too often or if the tracked list requires some time to stabilize.
So it’s not a bug, it’s about bad documentation and, well, a design mistake happened long ago, I admit. I was pretty sure it’s reflected in docs, but seems it’s not. I’ll fix documentation, but design is widely used so I can’t change it without breaking a lot of things, sorry.
from jquery.my.
Updated docs:
from jquery.my.
@ermouth it doesn't make any sense that the errors don't disappear after the child form is valid again.
Why are the errors added when the check
function is invoked but don't get erased when the child form is valid again? If they are added when the check
function returns a string (the error message), it's possible that they get erased too when the function doesn't reeturn anything.
Resorting to hacks like ghost divs to achieve a somewhat simple functionality like ensuring form validation defeats the purpose of this library that is to simplify code. And it does a great job at it, I've managed to create a form with repeated child forms, each with select2 controls that one depend on another in a clear way. No more boilerplate code to copy values from controls to objects and vice-versa. This library is really great.
from jquery.my.
Well... looks like it was indeed a bug. Tested here and now the errors are being cleared.
from jquery.my.
it doesn't make any sense
The background of this behavior is pretty reasonable. By its nature the this.my.errors()
object is a tree which branches are named after control selectors. So inevitably if a control is a list, its error cannot be a string, only an object which is a collection of subform error objects. You just can’t put any list error message into object, which makes functional validators merely useless. We can reflect (or not) underlying errors automatically.
Also if a list could apply .my-error
css class to itself on error, it would mark – visually – all inner controls as also having errors, which is awful in terms of ui.
So it is as it is.
Resorting to hacks like ghost divs
The ‘hack’ of proxy objects combining states of other controls is a long standing very standard practice employed by different platforms and frameworks, starting with old IBM mainframes. I didn’t invented it.
It doesn’t need to be a ghost, it may be Save
button which disables on errors, however ghost proxies are also very useful.
Tested here and now the errors are being cleared
In a way you did it it will not be accepted, it breaks a lot of things, and you put it in wrong part of code, sorry. I’ll think how to make it properly.
As I understands specs are:
- if we have a check function for lists, it receives list data array, and returns a string;
- the sheer presence of
.check
function for a list means we do not even try to collect errors from subforms and always rely on that function; - this function knows nothing about errors in subforms.
This might be reasonable. Here is one missing part: how to deal with .my-error
class, should it be applied on a list container? Any thoughts?
from jquery.my.
how to deal with .my-error class, should it be applied on a list container?
It shouldn't be applied at all when the check
function is at the "list" level and not "single control" level, you just don't have enough information about which control is invalid, and there's no way to guess it, apply it to the list container level would be really terrible because it would turn everything red. 😆
On this line, you was expecting that list form objects entered the if
block, thats why I added the isList
condition to the if
.
from jquery.my.
Maybe something like this would give the necessary information:
// list level
check: function (d, v){
const emptyNameIndex = v.findIndex(t => t.name == "");
if (emptyNameIndex !== -1)
return { control: "#name-input", index: emptyNameIndex, message: "Name cannot be empty." }
}
Then, you would have the offending control selector. Maybe the index
property gives some clue about which element of the form list will get the .my-error
class. Considering that the data array order and the form list order are the same. Form lists are really tricky.
And, yeah, smells like breaking changes... maybe.
from jquery.my.
Error message should be a string, or a dict of selector:error|dict pairs, otherwise we get inconsistent structure of errors object.
As I see it, subforms and lists containers may just receive another error class name, not .my-error
, but, say, .my-error-list
or smth. It might allow automatic error tips show/hide with css only, and all that stuff.
If a function wants for some reason return an object, it might be an artificially recreated object of standard error structure, with additional ""(empty string) key for meta-error message (I mean a message for entire block, which goes into error-tip obj automatically). Or, if no errors, we just return empty string or {}
or {'':''}
.
from jquery.my.
Btw this way of validation has one huge issue: it’s O(n^2), each subform change induces validation of all rows in a list. So proxy isn’t so bad idea after all.
from jquery.my.
Related Issues (20)
- Styler corrupts @keyframes sections
- Cannot use Enter in textarea in nested form. HOT 2
- $.my.locale does not change default locale HOT 1
- 引入my.js报错 HOT 1
- isS is not a function HOT 1
- Internal radio events reach only first listener
- Modal issues HOT 1
- Data only updates once HOT 2
- Issue with browser autocomplete forms HOT 1
- Validation error message not working on custom validation function HOT 2
- isS is not a function HOT 5
- Awesome job !! HOT 1
- Support binding for inputs of type "tel" and "email" HOT 2
- List renderer drops rows, which hashes are like obj default methods ("constructor", "valueOf" etc)
- Detecting change in linked field HOT 2
- it could not run with sugar 2.0.4 HOT 2
- Identify which event caused the control to redraw/recalc (invoked bind function) HOT 2
- does it support a grandson list form? HOT 2
- how to set a value HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery.my.