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.

[Form Validation] Should Pick up on DOM Changes

See original GitHub issue

There 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:open
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
lubber-decommented, Oct 6, 2022

@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/

0reactions
cueedeecommented, May 25, 2018

@stale-bot; this i getting annoying. If it’s not closed it’s not closed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Client-side form validation - Learn web development | MDN
This is called form validation. When you enter data, the browser and/or the web server will check to see that the data is...
Read more >
jQuery validation of a form inserted into DOM - Stack Overflow
Try to debug and step into the $('form').validate(). There is a point wherr jQuery attaches the validations on the form (if it hasn't...
Read more >
Form Validation with JavaScript
This tutorial will show you how to create a JavaScript-enabled form that checks whether a user has filled in the form correctly before...
Read more >
9. Form Elements and Validation - JavaScript Cookbook [Book]
If you want to validate a form field after the data in the field has changed, you can assign a function to the...
Read more >
React Bootstrap Form Validation - Abstract API
Any changes that are applied to the DOM with Bootstrap via JQuery do not get picked up by React. React Bootstrap eliminates the...
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