JQuery JEditable stay in edit mode on error

試著忘記壹切 提交于 2019-12-07 17:25:07

问题


I'm successfully using jeditable to submit via a function using jQuery.ajax and the async : false option , but am having an issue aborting if an error is returned.

How can I get the edit box to stay activated and / or revert back to the original value if there are errors? I'm returning http status codes.

so something like

async : false .ajax submit here...
if (xhr.status == 200) {
  return value;
else {
  alert ('returned error');
  // keep edit box activated but available for another try, or revert back to original value
}

I tried not returning a value from the function, which keeps the edit box activated and ready for another submit, but then the ESC key doesn't work anymore and if I click outside the edit area, the edit box stays.

Thanks in advance!


回答1:


Not sure if this helps in your situation, but jeditable has a reset method in it...

try...

this.reset();

this will revert the element back to display mode with the original value.




回答2:


To stay in editmode,just set response header "HTTP 404" and render a error text.

PHP:

header('HTTP/1.1 400 Bad Request');
echo "Error Text";



回答3:


Add this:

$(this).editable("disable");

This should stop your errors from being editable, not sure about reverting back. I am kinda fighting the same issue with reverting back right now, but i know nothing about JavaScript...



来源:https://stackoverflow.com/questions/727973/jquery-jeditable-stay-in-edit-mode-on-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!