Is there any way to use promise with a custom rule on semantic ui? I want to validate a field with my custom rule. If response of server is false field must be red. Here's what I'm trying to do.
$.fn.form.settings.rules.myCustomRule = function(param) {
let myPromise = this.get('api').r_get(allUrls.urlName, model);
myPromise.then(
response => {
return true;
}
).catch(
error => {
return false;
}
);
}
You can add error
class to a div or input when the promise returns false. Would that work? Like this:
function simulateServer(){ $('#serverresponse').addClass('error'); }
<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.3.3/semantic.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="serverresponse" class="ui input"> <input type="text" placeholder="Search..."> </div> <br><br> <button onclick="simulateServer()">Contact Server</button>
It wouldn't be possible with a custom rule promise, as it expects an immediate response.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.