Closed jasonivers closed 7 years ago
Hi
Thanks for the detailed explanation
<%= simple_form_for @task, remote: true, authenticity_token: true, validate: true, html: { id: 'task-form', validate: true, novalidate: false, data: { validate: true } } do |f| %>
why are you adding html: { id: 'task-form', validate: true, novalidate: false, data: { validate: true } }
? This should not be needed.
Unfortunately I cannot replicate your issue.
Model
class Task
include ::ActiveModel::Model
attr_accessor :taskable_id, :taskable_type, :reload_details, :name
validates :name, presence: true
def new_record?
false
end
end
View
<%= link_to 'Create Task', :new_task, remote: true, class: 'new-task-j' %>
<div id="new-task-container-j"></div>
Task view, loaded remotely
<%= simple_form_for @task, remote: true, authenticity_token: true, validate: true, html: { id: 'task-form' } do |f| %>
<div class="form-inputs width-full margin-large">
<%= f.hidden_field :taskable_id %>
<%= f.hidden_field :taskable_type %>
<%= f.hidden_field :reload_details, value: true %>
<%= f.input :name, placeholder: 'Example Task Name' %>
</div>
<div class="mdl-card__actions">
<a href='#' class='mdl-button mdl-js-button mdl-button--deemphasized' onClick='modal.close();return false;'>Cancel</a>
<button type="submit" class='mdl-button mdl-js-button mdl-button--primary' id='save'><%= @task.new_record? ? 'Create' : 'Update' %> Task</button>
</div>
<% end %>
Ajax loading:
$(document).on 'ajax:success', '.new-task-j', (e, data, status, xhr) ->
$('#new-task-container-j').append $(data).find('#task-form')
$('#task-form').enableClientSideValidations();
Result:
Closing here.
I will reopen if you provide a reproducible test case
When I try to use client side validations on a form loaded by AJAX, I get an error any time it tries to actually run validations (i.e. on focus, on blur, etc.), though not on the actual enableClientSideValidation() call:
I have it running the following code after updating the document:
I looked through the code in the actual gem, and I pulled some of what enableClientSideValidations() does, and it works if I call it directly:
Doing some debugging, it's pretty clear that
$(form).data('clientSideValidations')
(this in my code, due to simplification) is failing to read the data when executed via enableClientSideValidations(), as it is undefined, while addError and removeError are defined (but broken, because they rely on information from the settings data). I don't have any further time to invest in debugging this right now, since I have a functional workaround, but if you have specific things you'd like me to test, I can.I'm using: