Page 1 of 4

Access dynamic created Input Control that is selected by a user.

Posted: Mon Sep 09, 2013 11:44 am
by Pete Nellmapius

I have a Grid with 2 columns. The first contains a label and the second an input control (number).
The grid is connected to a datasource and the label to a field in the datasource. The Input controll is not connected.
When the Datasource is Invoked the Grid expands to contain all the records.
I want to evaluate the Input control's value on the 'Value Change' event when the user types in a value.
I also want to loop through the input controls which would be an array of controls and retrieve the values in them.
Can anyone help me.


Access dynamic created Input Control that is selected by a user.

Posted: Mon Sep 09, 2013 1:16 pm
by Maryna Brodina

Hello!
<[quote:]I want to evaluate the Input control's value on the 'Value Change' event when the user types in a value.[/quote]
If you added "Value change" event for Input component which is inside Grid then you would need to use the following JS:
codevar inputValue = $(this)&#46;val();/code
[quote:]I also want to loop through the input controls which would be an array of controls and retrieve the values in them. [/quote]
to retrieve array from Input components:
codevar valuesArray = [];

$("[name=gridComponentName]:visible")&#46;find("input")&#46;each(function(){
valuesArray&#46;push($(this)&#46;val());
});/code
gridComponentName - name of Grid component which is mapped to array
After you invoke this code into "valuesArray" array will be saved values of all Input components.


Access dynamic created Input Control that is selected by a user.

Posted: Mon Sep 09, 2013 2:45 pm
by Pete Nellmapius

Thanks Marina
Now my Input Control is set to type 'number' but I can still enter any character type.
Is there a way to force numeric input only and say between 0 and 3


Access dynamic created Input Control that is selected by a user.

Posted: Mon Sep 09, 2013 3:49 pm
by Anton Artyukh5836028

Hi Pete,

Simplest solution is use KeyPress Event with code like this:

prevar code = arguments[0]&#46;charCode;
if (code < 48 || code > 58) { &#47;&#47; codes from 48 to 58 describe 0&#46;&#46;9
arguments[0]&#46;preventDefault();
}/pre

But, user still can paste text to the field from clipboard. So you can try use Value Change event to check full value ( Appery( "mobileinput_name" ).val() ).


Access dynamic created Input Control that is selected by a user.

Posted: Mon Sep 09, 2013 4:08 pm
by Pete Nellmapius

Thanks Anton
On the 'Value Change' event I evaluate the value as you showed above.That's great.
The user may click into another field that fires the Change event.
How do I set the focus back to the input control I've just evaluated?


Access dynamic created Input Control that is selected by a user.

Posted: Mon Sep 09, 2013 4:24 pm
by Anton Artyukh5836028

preAppery( "mobileinput_name" )&#46;get(0)&#46;focus();/pre This code will set focus to input field with name mobileinput_name.


Access dynamic created Input Control that is selected by a user.

Posted: Mon Sep 09, 2013 4:46 pm
by Pete Nellmapius

That does not help me because I do not know the input field's name
Look at the top of this thread:

here is my code:
var inputValue = $(this).val();
inputValue = parseInt(inputValue);

if (Math.floor(inputValue) == inputValue) {
if (inputValue < 0 || inputValue 5) {
alert("Value must be between 0 and 5")
$(this).val(null);
$(this).focus();
};
}

$(this).focus(); does not change the focus;
This is not critical but would be great to be able to do this.


Access dynamic created Input Control that is selected by a user.

Posted: Mon Sep 09, 2013 4:50 pm
by Anton Artyukh5836028

Ok, sorry,

Try this: pre$(this)&#46;get(0)&#46;focus();/pre


Access dynamic created Input Control that is selected by a user.

Posted: Mon Sep 09, 2013 4:54 pm
by Pete Nellmapius

I did try that but it also does not change the focus.


Access dynamic created Input Control that is selected by a user.

Posted: Mon Sep 09, 2013 4:58 pm
by Anton Artyukh5836028

Does your code show alert?