AnsweredAssumed Answered

check_form more validations in users (bwc)

Question asked by Adrian Arauz on Jun 11, 2019

Actually i have a custom validation into Users module (in a .js file created to validate the password rules) but i need to create to more validations in that module in two new fields.

 

In the validation of passwords i have:

 

SUGAR.util.doWhen("typeof(check_form) != 'undefined' && typeof check_form == 'function'", function() {
    check_form = _.wrap(check_form, function(originalCheckFormFunction, originalCheckFormFunctionArg) {

//Logic of the validations (rules of passwords, names, numbers, capital letters, etc)
return originalCheckFormFunction(originalCheckFormFunctionArg);

}else{
    return originalCheckFormFunction(originalCheckFormFunctionArg);
}

});
});

I see this returns, that i think return my "function" and the "EditView" but adding my new validations (two of them into a two new fiels) i have en error with that because one of my validations "enter" and show me the message if my condition not match (shows alert) but it they matchs, saves the value into db of that field but... nothing happens
Im using the another names to use the method sugar.util.doWhen with the name of field and the paramethers of my return but not works. I have something like that:

 


SUGAR.util.doWhen("typeof('check_form') != 'undefined' && typeof check_form == 'function'", function() {
    check_form = _.wrap(check_form, function(originalCheckFormFunction, originalCheckFormFunctionArg) {

        //Validación para comparar ID
        var uni2= document.getElementById("tct_id_uni2_txf_c").value;
        var user = app.controller.context.attributes.model.id;

        if (uni2!="" && uni2!= undefined) {
            if(user=="" || user== undefined){
                user="x";
            }
            app.api.call('GET', app.api.buildURL('IDUsuarios/2/' + uni2 +'/'+ user), null, {
                success: function (data) {

                    if (data != null) {
                        if (data.valor>0) {
                            alert("El ID ingresado ya existe");
                            return false;
                        }
                    }
                    return originalCheckFormFunction(originalCheckFormFunctionArg);
                },
            });
        }else{
            return originalCheckFormFunction(originalCheckFormFunctionArg);
        }

    });
});

 

 

Anyone can help me with this?

 

Cheers.

Outcomes