sap.m.CheckBox binding - checkbox

I tried to bind a checkBox to an OData field, its type is Edm.Boolean. I can done the binding but it behaves like one-way binding, the chekbox shows the right statement when I ask for the value, but when I change the checkbox from checked to unchecked or vica verse, and save it, it will not update the value of the field.
xml view:
<CheckBox id="Seen"
selected="{= ${Seen} === 'true'}"
text="Seen"
enabled="true" />
However, if I change the value in an input box next to the checkbox it takes effect on the checkbox, but the checkbox can not take effect on the input field...
Input xml:
<Input value="{Seen}" valueLiveUpdate="true" />
Am I missing something?
Thank for any help in advance!

That happens because you are using an expression binding, which works quite similar a
formatter function. On these scenarios, even if your model is set to use 2 way data binding, this particular binding work only one way.
You should apply the binding on the checkbox on the same way you did for the Input.
<CheckBox selected=“{Seen}” />

Related

Datagridview checkboxes lose checks

In my Winforms app, I have a form that contains a datagridview with a checkbox column. If I check one or more checkbox items, then make a change to some other control on the form (outside of the datagridview), the checkboxes become unchecked. Any help would be appreciated. Thanks.
More details: The underlying binding for the checked items is working correctly, as the values are being stored and the checked states are correct when the form reloads. This is just a visual issue.
Furthermore, the checkbox value is never programmatically set to false in the code. False values only come from the binding or from being manually unchecked.
Redesigned the binding and now it works fine. Was previously maintaining a list of selections in the business object and checking checkboxes based on the selections. Now maintaining a "selected" property in the business object and binding appropriately.
Problem manifested as described due to nature of events generated by checkbox editing (apparently). Binding source change event not triggered when clicking the checkbox (since it was not bound) - only occurred after editing complete on another control.
Could you do an "Invalidate()" on the column to see if a redraw changes anything? Without code, we need to divide the problem arbitrarily.

Reset a ComboBox

I have a view that contains several ComboBox elements. For some reason old data remains from the previous time the view was opened and I would like to reset the combobox elements in the view every time it is opened. Is there a function that could that for me? I want it to be exactly how it is as if I rendered it the first time with the initial items. Would using setSelectedItem(vItem), setSelectedItemId(vItem), setSelectedKey(sKey), setShowSecondaryValues() help? If so, what do these keywords mean (selectedItem, selectedItemID, selectedKey, secondaryValues)?
Unfortunately you do not provide an example. Normally you bind your UI controls against a model, e.g. JSONModel. In this case the items of your ComboBox controls would be taken from the corresponding model. However, you can use method removeAllItems to achieve the desired behaviour.
UPDATE: Obviously the controls are bound and only the selection should be cleared.
Use setSelectedItem with value null to clear the selection. You could also use the binding to set the selected item automatically by using the selectedKey attribute, see example.

How to validate field that's not bind to any element

I have one field that's not bind to any form element, but I would like to add required validation to it like I have for any other fields that are bind to some controls. I tried to use
<input type="hidden" name="requiredField" ng-model="vm.requiredField" required />
but while field was marked as $invalid and the whole form was still $valid.
Do you have any idea how to make such validation?
Eventually it looks like it should works. The reason why it doesn't work for me is because there was hidden code that changed $invalid field manually. I found it by using such script: https://github.com/paulirish/break-on-access

Have Checkbox checked by default in UI

I am trying to add a new checkbox into a UI screen for my installer.
So far I have declared the property as seen below:
<Property Id="RS232" Value="1" Secure="yes"/>
And in the UI, my checkbox has been added as:
<Control Id="myNewCheckbox" Type="CheckBox" X="200" Y="170" Text="Generic Driver" Width="130" Height="15" Property="RS232" CheckBoxValue="1"/>
From documentation I have read I am lead to believe that as long as CheckBoxValue and Value are equal i.e 1 in this case, then the checkbox should be checked by default.
There are already existing checkboxes on this same UI and this is true for them, so I do not understand why in my additional case, the checkbox is not active.
Another note to be made is that when I go through the installation process to test the new checkbox, the dialog disappears when I hover over it with a mouse and I am unable to check/uncheck the box.
I first thought that perhaps the Width field for the text was not big enough, but I have tested by expanding this with no results.
Any help is appreciated!

Clicking text to select a checkbox

I noticed that on certain websites, if you want to tick a checkbox on or off, you just need to click the corresponding text. When I put a checkbox with some descriptive text on my page, I have to actually hit the checkbox for it to get ticked. How is the former effect achieved?
Consider using a <label> as in this example:
<input type="checkbox" name="call" id="willcall">
<label for="willcall">click on this text to select the checkbox</label>
This example from: http://www.askdavetaylor.com/make_text_adjacent_to_checkbox_clickable.html
I'm sure that they use a JS script to achieve this. It's most likely a label that is being clicked, and they might add an onclick() event to the label which uses the javascript to find the checkbox and add the CHECKED attribute to it. Sorry for not supplying code, but I hope that gives you some understanding on what those websites do.

Resources