wv.wilson75
Posts: 0
Joined: Fri Dec 30, 2011 2:53 am

Required Field . . . How to?

How can I gray out a button if a input field is blank?

Please be as detailed as possible... Still learning here.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Required Field . . . How to?

Do you want to do something like this but with an input field: http://gotiggr.com/preview/24099/mob-...

wv.wilson75
Posts: 0
Joined: Fri Dec 30, 2011 2:53 am

Required Field . . . How to?

Yes . . . just want it grayed out like that unless they have typed into the input field.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Required Field . . . How to?

On page load, run this JavaScript:

code
var button = Tiggr('button');
button.addClass('ui-disabled');
/code

Add 'value change' event to input field and run this JavaScript:

code
var input = Tiggr('input').val();
var button = Tiggr('button');

if (input == '') {
button.addClass('ui-disabled');
}
else {
button.removeClass('ui-disabled');
}
/code

Input field name is 'input', button name is 'button'.

Sample app: http://gotiggr.com/preview/24099/mob-...

wv.wilson75
Posts: 0
Joined: Fri Dec 30, 2011 2:53 am

Required Field . . . How to?

I am good with the second step here, but how do I set the first part on page load? I am not seeing an option for a javascript.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Required Field . . . How to?

Click outside the phone frame, switch to Events tab. You will be able to add load event and then Run Custom JavaScript action.

Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Required Field . . . How to?

Thanks for this Max.

Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Required Field . . . How to?

Ok I have 3 fields on a registration form that I want the user to fill before the register button becomes enabled. Username, Password, Email

  1. When i put the code as explained in this topic, I noticed that if the user just fills one of the fields the register button is enabled.

    username on value change code:
    precode
    var input = Tiggr('username').val();
    var button = Tiggr('registerbutton');

    if (input == '') {
    button.addClass('ui-disabled');
    }
    else {
    button.removeClass('ui-disabled');
    }
    /code/pre

    Password on value change code:
    precode
    var input = Tiggr('password').val();
    var button = Tiggr('registerbutton');

    if (input == '') {
    button.addClass('ui-disabled');
    }
    else {
    button.removeClass('ui-disabled');
    }
    /code/pre

    Email on value change code:
    precodeemail').val();
    var button = Tiggr('registerbutton');

    if (input == '') {
    button.addClass('ui-disabled');
    }
    else {
    button.removeClass('ui-disabled');
    }
    /code/pre

  2. I then did some changes by removing the else part on the username and password and leaving it on the email field only. But the problem with this approach is that if the user just fills in the email field and leaves the username and password blank the register button is enabled.

    username on value change code:
    precode
    var input = Tiggr('username').val();
    var button = Tiggr('registerbutton');

    if (input == '') {
    button.addClass('ui-disabled');
    }
    else {

    }
    /code/pre

    Password on value change code:
    precode
    var input = Tiggr('password').val();
    var button = Tiggr('registerbutton');

    if (input == '') {
    button.addClass('ui-disabled');
    }
    else {

    }
    /code/pre

    Email on value change code:
    precodeemail').val();
    var button = Tiggr('registerbutton');

    if (input == '') {
    button.addClass('ui-disabled');
    }
    else {
    button.removeClass('ui-disabled');
    }
    /code/pre

    Is there away to enable the register button only when all the fields are filled?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Required Field . . . How to?

Hello! You have to check all the input fields. Better to check it for all three inputs, because if the user fills first Email field and then fields above - the button will stay disabled.
For example create function checkInputs(){} and check there all three inputs. Then call that function on "value change" input fields.

Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Required Field . . . How to?

Ok Thanks I'll give it a try.

Return to “Issues”