Home  >  Article  >  Web Front-end  >  Solution to the conflict between xheditor and validate plug-in_jquery

Solution to the conflict between xheditor and validate plug-in_jquery

WBOY
WBOYOriginal
2016-05-16 18:29:131218browse
xheditor and validate are both excellent jQuery plugins, but combine both Combined, if the order of initialization is not correct, some subtle results can occur. I used these two plug-ins at the same time when making a text submission page. One is used to display the rich text editor, and the other is used to verify whether the user has filled in the content. My initialization code is as follows:
Copy code The code is as follows:

$("#form1").validate({
rules: {
Body: "required"
},
messages: {
Body: "Please fill in the text"
}
});
var editor = $("#Body"). xheditor(true, {
tools: "simple"
});

But when submitting, even though the content has been filled in, "Please" is still displayed when the submit button is clicked for the first time. "Fill in the text", and it will not be submitted until the second time I click the submit button. This phenomenon makes me puzzled. What is the problem?

Because there are multiple pages in the current project that use these two plug-ins, and one of the pages was normal when submitted, so I carefully compared the similarities and differences between the normal and problematic pages, and found that The order of initialization is different. In the page that can be submitted normally, xheditor is initialized first, and then validate is initialized, but the page in question is just the opposite. It turns out to be like this! The problem has been solved at this point. As long as the initialization order of the two plug-ins is reversed and xheditor is initialized before validate, the "double submission" problem can be avoided.

Hope this article is helpful to you.

CKEditor also has this problem. My solution is to get the content in the Editor and put it into the textarea.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn