Forums

Forums / Developing Portals / Invalidated text field programmatically

Invalidated text field programmatically

Thread is closed for posting
3 posts, 2 answered
  1. julien.biedermann
    julien.biedermann avatar
    17 posts
    Registered:
    16 Jun 2016
    20 Jun 2016
    Link to this post
    Hello,

    I have a text box for the password confirmation on a form. If the textfield (last known password) and the textbox (password confirmation) do not match, is it possible to invalidate the last known password field in order to prevent form submission and display errror message ?

    Thank you for your help
    Julien
  2. mbayes
    mbayes avatar
    17 posts
    Registered:
    29 Dec 2015
    Answered
    20 Jun 2016 in reply to julien.biedermann
    Link to this post
    Hi Julien,

    If I understand correctly, you have a Sitefinity Text Box control, as well as a CRM Text Field control. From the sounds of it, you will have to use Javascript to validate the inputs on form submit. What you can do is in the TB control you can add a custom class, say "tbPassword". In a Javascript block, you can add code similar to this:

    function ValidatePassword() {
        var tb = document.getElementsByClassName("tbPassword");
        var tf = findControl("CrmTextField_C001");

        if (tb.innerText != tf.get_value())
        { return false; } else { return true; }
    }

    As you can see, we can reference TPC controls using findControl but need to use DOM manipulation to retrieve the TB value. Returning FALSE from the function will prevent form submissions. To make this work, on your submit button you should see a "OnClientClick" property in the Advanced window. Adding the name of the function here prefixed with "return" ( ie, return ValidatePassword() ) will call the function, verify the two field values, and then either return false (stop submission) or true (continue with submission).

    To display a message to the user, you can throw in an "alert" step in the function while will display a pop-up to the user with whatever message you want.

    Hope this helps, or at least gives you an idea on where to begin.

    Thanks.

    Matt Bayes
  3. Clinton Bale
    Clinton Bale avatar
    126 posts
    Registered:
    21 Feb 2014
    Answered
    21 Jun 2016 in reply to mbayes
    Link to this post
    Hello,

    Matt thank you for your example. It is complete except for a minor issue. When overriding the "OnClientClick" ​JavaScript you must make sure to only return if the result is invalid. Otherwise the TPC logic will not kick off and run in any case.

    Here is what you should add to the OnClientClick to check for matching passwords:

    if(!ValidatePassword()){return false;}
    
    Last modified on 21 Jun 2016 16:06 by Clinton Bale
3 posts, 2 answered