Created
March 7, 2021 12:09
-
-
Save mthri/c8e89bf417c49c0a56eb4640d4e2a9c6 to your computer and use it in GitHub Desktop.
show ajax response error with jq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
<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