knockout.js - knockout html binded form cannot be changed to show validation error -
hi have viewmodel contains form string in observable
var viewmodel = { form: '<label>name</label>' + '<input type="text" name="name">' '<label>name</label>' + '<input type="text" name="class">', };
in html have used viewmodel this;
<em data-bind="html: form"></em>
here want append validation error msg after label tag using jquery. not able form attribute of view model constant. if change html goes again constant state. how can solve problem please help.
not answer may want hear, posting nonetheless...
you need rethink approach.
the html
binding suited inserting (trusted) snippets of html content application, e.g. sanitized bit of content cms. it's not suited loading more parts of application, not in least because bindings not applied new dom bits.
it seems you're trying load parts of application dynamically. using view models determine when/which/how load parts thing, mechanics better left other instruments in knockoutjs toolbox. specifically, should have @ knockoutjs component
task. alternatively, use template
s instead.
as footnote, there few more specific issues mention well:
- you try load form inside
em
tag? beware of content , isn't valid or sensical inside such tag. - you want use jquery validation, should have @ ko-validation or knockout-friendly integration between jquery-validation , ko;
- the
form
property not observable, why use ko render in first place? perhaps vanilla js or plain jquery better choice?
final note, indicated op in comments, if insist on keeping approach, there's different question contains solution. see: "data-bind on dynamically generated elements".
Comments
Post a Comment