Page 1 of 1

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

Posted: Thu May 15, 2014 11:26 pm
by Roger

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 ();


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

Posted: Fri May 16, 2014 12:42 am
by Yurii Orishchuk

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.


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

Posted: Mon May 19, 2014 1:52 pm
by Roger

This will do what I need...Thank You!!


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

Posted: Tue Jun 03, 2014 4:42 pm
by Roger

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?


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

Posted: Tue Jun 03, 2014 9:48 pm
by Yurii Orishchuk

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.