4

Hi I am new in semantic ui framework and I want to make the validation like email already exist or username already exist .so what I am doing I have made a custom rule and run the ajax for checking email or username already exist or not.... Please check bellow code ex. of email already exist

email: {
    identifier: 'email',
    rules: [{
            type: 'email',
            prompt: 'Please enter a valid e-mail'
        },
        {
            type: 'alreadyExistemail',
            prompt: 'This email is already registered, please choose another one.'
        }
    ]
}
$.fn.form.settings.rules.alreadyExistemail = function(param) {
    return Check_existence(param);
}

function Check_existence(param) {
    //Here I am running ajax which is communicating with db and returning true or false.
     var a;
      $.ajax({
            method: "POST",
            url: ajax_url,
            async:false,
            data: { 'action': 'checkEmailalreadyexist','email':param},
            success: function (data) {
                a = data;
            }
        });
        return a;

}

But Problem is that Ajax is running with every single typed alphabet and I want (for specific field) it should first validated by other rule then custom rule functionality work. so is it possible I can check other rule valid in custom rule like that

$.fn.form.settings.rules.alreadyExistemail = function(param) {
    if (is valid(email)) {
        return Check_existence(param);
    }
}

or can any one please suggest how can I make validation like email already exist or username already exist in semantic ui form?

  • A simple if statement is probably the way to go. But *return* probably wont work with an asynchronous ajax call... – Jonas Wilms Jul 26 '17 at 10:55
  • @Jonasw Simple - `Here I am running ajax which is communicating with db and returning true or false.` is not a valid JS code + calling that function from `return Check_existence(param);` (remember that function is async). Lsat thing - Poor formatting. It was my DV and i'm proud of it – Alon Eitan Jul 26 '17 at 10:56
  • @Jonasw I totally agree about the helping people out part, but if it was only the formatting than I would edit it. But when I see that the OP dropped very important part of the code, and left us "guess" it, then I don't see any way I can really help him (Nothing here is personal of course). – Alon Eitan Jul 26 '17 at 11:02
  • @alon eitan hey its his first question, tell him what to do better, then he can improve his answer and isnt frustrated because it rains downvotes... – Jonas Wilms Jul 26 '17 at 11:05
  • 1
    @AlonEitan I'm not saying that your DV was right or wrong, but in my opinion, down voting without leaving a reason is not that helpful. Many people do these "drive by down votes" while the OP got no clue why. That's not encouraging for anyone. – M. Eriksson Jul 26 '17 at 11:05
  • @ashish welcome to SO ;) . As you may have noted from the discussion above, your question is unanswerable yet. Please replace *Here am i running...* with real code, theres probably an error. And *is* isnt valid in js too... If you fix that, we can hopefully help ;) – Jonas Wilms Jul 26 '17 at 11:07
  • @AlonEitan I have edit it. can you please check it again? – ashish jogi Jul 26 '17 at 11:09
  • Ok, im not able to help you as i dont know much about semantic-ui, however if you would accept a pure js/css/html answer, i would give it a try. Please have a look at this to get an overview of the problem https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – Jonas Wilms Jul 26 '17 at 11:12
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Alon Eitan Jul 26 '17 at 11:36
  • Just as a personal side note: Is it specifically required to inform the user that there is an account with this email ? It generally leads to some nefarious person(s) checking.. But it's all relative of course. – Pogrindis Jul 26 '17 at 11:36
  • @ashishjogi Please read the duplicate - You can't return the response from an async call the way you did. I retracted my downvote BTW – Alon Eitan Jul 26 '17 at 11:38
  • @AlonEitan Please check I did async:false . – ashish jogi Jul 26 '17 at 11:47
  • 1
    @MagnusEriksson Sorry I missed your comment, and I think you're right about leaving a reason - Although it's not mandatory, it can help users know what's wrong with their post before it gets closed. I did retracted my DV, and will take your comment as a constructive criticism. Thanks – Alon Eitan Jul 26 '17 at 14:22

0 Answers0