[Form Validation] Should Pick up on DOM Changes
See original GitHub issueThere appears to be a problem with this code taken from src/definitions/behaviors/form.js
:
module = {
initialize: function() {
// settings grabbed at run time
module.get.settings();
if(methodInvoked) {
if(instance === undefined) {
module.instantiate();
}
module.invoke(query);
}
else {
if(instance !== undefined) {
instance.invoke('destroy');
}
module.verbose('Initializing form validation', $module, settings);
module.bindEvents();
module.set.defaults();
module.instantiate();
}
},
...
settings: function() {
...
// grab instance
instance = $module.data(moduleNamespace);
// refresh selector cache
module.refresh();
},
...
… the effects of with are probably best demonstrated through this JSFiddle.
Afaict the problem is with the module.refresh();
line in the above code;
It’s still fine upon first invocation of .form()
when there’s no instance
yet and module
ultimately becomes the stored instance.
On successive invocations however - like a .form( 'get values' )
for instance - it is the invocation-module
that gets .refresh()
-ed and not the, now, stored instance
; so when instance.get.values()
is module.invoke(query)
-d it will work on the un-.refresh()
-ed values as demonstrated through the aforementioned JSFiddle.
I find that changing the above code to the one below appears to resolve the issue:
module = {
initialize: function() {
// settings grabbed at run time
module.get.settings();
if(methodInvoked) {
if(instance === undefined) {
module.instantiate();
}
+
+ // refresh selector cache
+ instance.refresh();
module.invoke(query);
}
else {
if(instance !== undefined) {
instance.invoke('destroy');
}
+
+ // refresh selector cache
+ module.refresh();
module.verbose('Initializing form validation', $module, settings);
module.bindEvents();
module.set.defaults();
module.instantiate();
}
},
...
settings: function() {
...
// grab instance
instance = $module.data(moduleNamespace);
-
- // refresh selector cache
- module.refresh();
},
...
… but I’ll leave it up to you guys to decide if this change is right, complete and sufficient.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
Top GitHub Comments
@cueedee I adopted your proposed solution for the community fork Fomantic-UI by https://github.com/fomantic/Fomantic-UI/pull/1811
See your adjusted, now working, jsfiddle here https://jsfiddle.net/lubber/s9p4moyx/3/
@stale-bot; this i getting annoying. If it’s not
closed
it’s not closed.