Knockout - doubling value in a focused textbox - javascript

I have a knockout model with observable arrays bound to a table. I want to have a button that when clicked, doubles the focused textbox value. I want to do this without having a create a 'hasFocus' observable for every textbox or every ko observable. Couple of issues I experienced :-
if the button just edits the value of the textbox directly using jQuery, the ko value does not get updated. I need a way to tell the button to change the underlying value
if I focus on a textbox then click a button, the focus on the textbox is lost so client side also doesn't remember what textbox is focused

Do an event binding on input on both focus and blur, setting and clearing an observable which tracks what input is active.
When the button is clicked you know which value to double

Related

Hidden focus on blur of an input element in dom

A little Explanation : I am using List view control of kendo UI(Telerik). I am triggering an update event of that control after editing the fields in list view. The list view control is having some text-boxes, a dropdown,checkbox and a submit button. When a user change something, ideally it should trigger update but its not doing update because control is not able to judge if there is a change in model.
It is only working if I input something in textbox and just click on outside of textbox i.e just do a onblur before hitting submit. I don't know why it is happening but what I need is to just trigger a focus event but in a hidden mode so that user is unaware of it but it just happens after a user input something in textbox so that the list view control works successfully.
I am trying to do it like below but it will get noticed to user. How can i trigger focus in hidden mode after a user just enter something in textbox before hitting a submit?
function BlurFunc() {
debugger;
$(this).closest('li').find('.inputField').focus();
}
Without your code it is not clear whether you are using MVVM data binding to your model, but this may help; from http://docs.telerik.com/kendo-ui/framework/mvvm/bindings/value:
By default the value binding relies on the change DOM event, which is
raised after blurring the element whose value has changed. This means
that the value from the View-Model is updated when the element loses
focus. The data-value-update attribute can be used to specify a
different DOM event, such as keyup or keypress. The keydown event is
not supported, because the DOM element value is not yet updated when
that event triggers.
For example, try adding data-value-update="keyup" as an attribute to your text box input element:
<input data-value-update="keyup" data-bind="value: inputValue" />
This should then update the model value upon each key press and not wait until focus has been removed.

How to detect changes in the asp panel through javascript?

I have many controls(like texbox,telerik grid, dropdown and radio button) on one asp panel.Could someone help me in detecting changes in any control of asp panel while clicking submit button.
There might be a better way of doing this, but my suggestion would be:
Create a hidden field that has a default value of "False". This hidden field will tell us if the form has changed or not.
Then assigning any editable control the JavaScript OnChange event.
The OnChange event should call a simple method that sets the value of the hidden field to "True".
For example with jQuery it would be:
function FormChanged() {
$(".hiddenField").val("True");
}
Then when you submit you will be able to access the value of the hidden field to know wether the form has benn changed or not.

how watch to change angularjs model which checkbox changed from jquery

I use https://github.com/Dimox/jQueryFormStyler for styling form inputs.
I set the property ng-model="c.model.acept".
If I click on "styled checkbox", then input gets to property "checked", but the angular model still has the old value.
I tried to trigger the change event with no result.
If I trigger the click event, then the checkbox gets changed twice (once from click, and then the second time from the triggered click event).
How to fix it?
You can not change "ng-model" of particular input field conditionally.
In this condition what you can do is, keep two input field and use "ng-show" or "ng-if" attribute to show & hide input field conditionally.
Hope this will hep you.

dojo Select box, triggering events on select

Hi I am using a dojo select, I have a text box where a certain ID is entered and then based on what is chosen on the select box an action is performed. Now the problem is, suppose over two different requests the action remains the same and the id changes I cant trigger the function with the onChange event. How do i handle this? Even if the user opens the select box and chooses the same item as last time I want the function i've written to be called.
onchange fires when any option is changed of the combo box.In your case you are not changing the options so obviously that event will not fired.
You can try onclick instead.
Write the same code in onclick for the select element (however with some intelligent logic since onclick will keep on firing even before you are able to select any option which may not expected in your case..!).

javascript and dynamic data

I'm using Dynamic Data 4 on my project.
In a template field there's a button that modify (via javascript) the value of the databound input field.
The button modify the input box value correctly but when the input field get the focus his value it's resetted to the previous value. The same happens when saving the form. If the input box previously received input from the keyboard the value it's correctly stored.
Is that behaviour to be considered normal with those premises? There's a way to avoid it?
Thank you very much.
The problem was caused by the presence of an associated asp:TextBoxWatermarkExtender who resetted the value when the (originally null) textbox got the focus.

Categories