Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

No way to update cached inputs for forms with dynamic fields #306

Closed
methakon opened this issue Apr 6, 2016 · 9 comments
Closed

No way to update cached inputs for forms with dynamic fields #306

methakon opened this issue Apr 6, 2016 · 9 comments
Assignees

Comments

@methakon
Copy link

methakon commented Apr 6, 2016

Hi it is not working with dynamically generated field's
i have used ajax coll to add more button that use to add additional fields

by then when i press validate

function set_validator()
{
    console.log('----------');
     $('#v_form').validator();
}

it is ignoring the dynamically added folds is their is any solution

background i have done minimal alteration validator.js at $(window).on('load', function () but hope that will not effecting in this case

  $(window).on('load', function () {
    $('form[data-toggle="validator"]').each(function () {
      var $form = $(this)
      Plugin.call($form, $form.data())
    });
    $( ".form-group" ).each(function( index ) {
        if($(this).find('.help-block').length== 0)
        {
            var hb= document.createElement('div');
            hb.className ='help-block with-errors';
            this.appendChild(hb);
           // console.log(this);
        }

        });
  });
@1000hz
Copy link
Owner

1000hz commented Apr 6, 2016

The validator is caching the fields at initialization for performance. I'll need to add a refresh method to the plugin you can call to update the cached inputs.

@1000hz 1000hz self-assigned this Apr 6, 2016
@1000hz 1000hz changed the title not working with dynamically generated filds No way to update cached inputs for forms with dynamic fields Apr 6, 2016
@methakon
Copy link
Author

how to do it

@corganhejijun
Copy link

by comments one line in validator.js,i solve this problem temporary.

 function Plugin(option) {
    ……
      if (!data && option == 'destroy') return
      //if (!data)  **-------------comments this line at 331**
      $this.data('bs.validator', (data = new Validator(this, options)))
      if (typeof option == 'string') data[option]()
    })
  }

@DHorchler
Copy link

@corganhejijun , sorry, your temporary solution did not work in my case.

@1000hz , any chance to see that refresh-method any time soon?
Or is there another solution for dynamically added form fields?
Thanks.

@1000hz
Copy link
Owner

1000hz commented Jun 17, 2016

I don't know when I'll have time to be able to work on the next version of the plugin, but you can use v0.9 in the meantime since it doesn't cache the inputs.

@GarethFox
Copy link

GarethFox commented Jun 22, 2016

That's exactly the issue I am experiencing.
I need to .attr('required') on showing up input depending on checkboxes or radio groups selections...
Did you say that v0.9 is the one that can temporary allow reloadind input for forms if using .validator('destroy'); then .validator(); again ?
Thanks!

Edit: @corganhejijun , your solution neither worked in my case.

@1000hz
Copy link
Owner

1000hz commented Jul 15, 2016

.validator('update') has been added to v0.11.0

@1000hz 1000hz closed this as completed Jul 15, 2016
@dmsaciklum
Copy link

how it can be used?

@Maransatto
Copy link

1000hz, it's been a greak work you've done here. But I'm really facing difficult to find an example of .validator('update'), or any other example that changes the attribute data-validate dynamically.
Can someone here help me?
Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants