Roger
Posts: 0
Joined: Fri Mar 29, 2013 1:10 pm

Why does val not return anything for an Input setup with type of number when entering a character?

I am using the following code below to extract value from Input control. When setting Input control with type = number the val returns nothing if a character is entered in the input control. I understand that when setting type = number ios/android will only produce number keypad but if running webapp you can still enter character. I wanted to get value and then use isNan to determine if a number was entered.

var val = Appery("Input_Text").val();
var val2 = Appery ("Input_Number").val ();

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Why does val not return anything for an Input setup with type of number when entering a character?

Hi Roger.

Limitation you've got is html correct behaviour. See details: http://www.whatwg.org/specs/web-apps/...

But we have workaround for you:

Please follow these steps:

1 Create new JS asset.

2 Populate just created JS asset with following code: http://prntscr.com/3jllxk/direct

precode

function GetApperyInputValue(inputName){
var input = Appery(inputName)[0];

Code: Select all

 if(!input) 
     return "&quot 

 input.focus(); 
 document.execCommand("SelectAll"); 
 var displayValue = window.getSelection().toString(); 
 document.execCommand("Unselect"); 
 input.blur(); 

 return displayValue; 

};

/code/pre

3 Use code below when you need to get the value from your input component:

precode

//Where "mobiletextinput_33" is your input component name.
GetApperyInputValue("mobiletextinput_33")

/code/pre

Regards.

Roger
Posts: 0
Joined: Fri Mar 29, 2013 1:10 pm

Why does val not return anything for an Input setup with type of number when entering a character?

Can I use the same name more than once for a component name if they are on different pages? Appery seems to allow this. If this is okay how would I reference them uniquely?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Why does val not return anything for an Input setup with type of number when entering a character?

Hi Roger.

Yes you can use the same name in diffrent pages(it's not recomended but permited).

In this case you should modify given code with following one:

precode

function GetApperyInputValue(inputName, pageName){
var input;
if(pageName)
input = jQuery('#' + pageName + ' [name="' + inputName + '"]')[0]
else
input = Appery(inputName)[0];

Code: Select all

 if(!input) 
     return "&quot 
 input.focus(); 
 document.execCommand("SelectAll"); 
 var displayValue = window.getSelection().toString(); 
 document.execCommand("Unselect"); 
 input.blur(); 
 return displayValue; 

};

/code/pre

And invoke this function with following way:

precode

//Get value of input with name "aaa" if there is only one input with this name.
GetApperyInputValue("aaa")

//Get value of input with name "aaa" on known page. There could be several inputs with this name on several pages.
//Note you need to pass screen name like "Screen4".
GetApperyInputValue("aaa", "Screen4")

/code/pre

Regards.

Return to “Issues”