0

After a page is rendered a field that was set to be required with KO to "data-value=true" is, after user input, not needed to be validated by JQuery unobtrusive validation. How can the attribute be updated to "false" so that the field will not be set to required?

I have tried unsuccessfully using f.attr("data-val", "false"), which updates the Object itself and not attr: item.

2 Answers2

0

Try using the knockout "attr" binding. http://knockoutjs.com/documentation/attr-binding.html

You could possible pass to the attr binding a KO observable that returns true / false. You could also create a custom KO computed observable which returns true / false based on other propeties on your view model (http://knockoutjs.com/documentation/computedObservables.html)

If you get stuck, post a 'cut back' sample of what you're trying to achieve, including your html and viewmodel javascript.

Damien Sawyer
  • 5,323
  • 3
  • 44
  • 56
  • thanks for the tip. However, turns out the solution was a little trickier than that. See the correct answer above. – user3254398 Feb 03 '14 at 22:23
0

The solution was to reparse the form.

The important lines of code are below.

currForm.removeData("validator");
currForm.removeData("unobtrusiveValidation");
$.validator.unobtrusive.parse(currForm);

The solution was found here. jquery.validate.unobtrusive not working with dynamic injected elements

Community
  • 1
  • 1