Skip to content

Instantly share code, notes, and snippets.

@mthri
Created March 7, 2021 12:09
Show Gist options
  • Save mthri/c8e89bf417c49c0a56eb4640d4e2a9c6 to your computer and use it in GitHub Desktop.
Save mthri/c8e89bf417c49c0a56eb4640d4e2a9c6 to your computer and use it in GitHub Desktop.
show ajax response error with jq
/*
<div class="form-group col-md-6">
<label for="organization-name" class="float-right">جزئیات نام</label>
<input type="text" class="form-control" id="organization-name" name="organization_name" required>
<div><ul class="errorlist text-right"></ul></div>
</div>
*/
function show_error(form, errors){
for (const [key, value] of Object.entries(errors)) {
target_element = $(form).find(`[name=${key}]`)
error_list_element = target_element.parent().find('.errorlist')
error_list_element.html(`<li>${value}</li>`)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment