How to call/ re-render a button in openui5 - javascript

I am using the below openui5 toggle button which is blue when pressed is true and grey when it is false. But the value of the button changes at some point of time. Is it possible to explicitly call the button to re render it.
var oToggleButton1 = new sap.ui.commons.ToggleButton({
text : "Auto-Update",
tooltip : "Update toggle.",
pressed : true,
press : function() {
if(oToggleButton1.getPressed() == true){
buttonStatus = "ON";
}
else{
buttonStatus = "OFF";
}
var oDialog1 = new sap.ui.commons.Dialog();
oDialog1.setTitle("Alert!");
//alert('Auto update is turned '+buttonStatus);
oDialog1.addContent(new sap.ui.commons.TextView({text: "Auto update is turned "+buttonStatus}));
//oDialog1.addButton(new sap.ui.commons.Button({text: "OK", press:function(){oDialog1.close();}}));
oDialog1.open();
oDialog1.close();
refreshButtonDisplay=oToggleButton1.getPressed();
},
layoutData: new sap.ui.layout.GridData({span: "L12 M12 S12"}),
}),

It is probably best to bind the ToggleButton's pressed property to a property in a model and let UI5's binding magic take care of all that. If UI5 sees that the property in the model changes, it will check the bindings of that property to see if there are any UI controls need an update as a result of that. If you have bound your ToggleButton to that property, UI5 will update/rerender the ToggleButton.
You could also change the "pressed" property of the ToggleButton directly from your controller, e.g.: oToggleButton1.setPressed(false) should also do the trick.

I did not really understand what you are trying to achieve, maybe you could elaborate a little more, i.e. what value changes and when? Anyway... jpenninkhof is absolutely right with everything he said. However, since you are explicitely asking for how to rerender the button here is the answer:
oToggleButton1.rerender();
This will rerender the button (based on its properties of course...).
However, calling
oToggleButton1.setPressed(false);
or
oToggleButton1.setPressed(true);
will rerender the button automatically in case the value for the pressed property has changed.

Related

How to manipulate data-binding, knockoutJs

I have a customer who is a member of a web site. He has to fill a form every time which is really very often. That's why he wants me to develop an application for him to make this process automatic. When I use the webBrowser control to manipulate it, I am able to login but after that there are fields that contains data-binding. These fields are the ones I need to manipulate. When I push the data to necessary fields, it's not working, because in the html tag, there is no value attribute, instead it has data-binding. So my question is how can I manipulate and push data to these fields?
Thank you so much for your all help in advance.
Knockout uses data-binds to listen to changes in an input and update an underlying model. For example, the value binding listens to change events and writes the new value to a data-bound observable.
If you update a value attribute through code, the change event isn't triggered. You'll see the new value in the UI, but the javascript model won't be updated.
You can combat this by explicitly triggering a change. Here's an example:
Type in the input: you'll see a console.log that shows knockout gets updated
Press the button to inject a new value: you won't see a log: knockout isn't updated
Press the last button to trigger a change event. You'll notice knockout now updates the model.
Of course, you can combine the two click listeners into one function. I've separated them to get the point across.
// Hidden knockout code:
(function() {
var label = ko.observable("test");
label.subscribe(console.log.bind(console));
ko.applyBindings({ label: label });
}());
// Your code
var buttons = document.querySelectorAll("button");
var input = document.querySelector("input");
buttons[0].addEventListener("click", function() {
input.value = "generated value";
});
buttons[1].addEventListener("click", function() {
// http://stackoverflow.com/a/2856602/3297291
var evt = document.createEvent("HTMLEvents");
evt.initEvent("change", false, true);
input.dispatchEvent(evt);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
<input type="text" data-bind="value: label">
<button>inject value from outside</button>
<button>let knockout know something changed</button>

When I set the 'required' property to 'true' the widget validation is not working

The widget seems to work as expected because the margin gets highlighted when I click inside/outside the textbox.
However when I set the required property the borders are not becoming red.
var widget = getWidget("id");
widget.required = true;
Is there any to change a property for dijit widget(TextBox) ?
You need to sue the setter for that:
getWidget("id").set("required", true);
Otherwise you change the property but the widget is not aware that property have changed

Getting value from mdl radio button

In the following code why doesn't the radio report the correct value when checked via its variable name?
var $myRadio = $('input[type=radio][name=options]:checked');
$('#button').click(() => {
// this works
console.log($('input[type=radio][name=options]:checked').val());
// this doesn't :(
console.log($myRadio.val());
});
https://jsfiddle.net/charsi/p4beztwx/13/
I am using mdl radio buttons so that could be causing it. I have also tried getting the value with $myRadio[0].MaterialRadio.value but that doesn't work either.
EDIT: This was a poorly worded question and didn't really have anythng to do with mdl. What I really wanted was the ability to set the DOM variable for my radio button somewhere else without having to select it by name again to check the value.
The reason for getting incorrect values when checked via its variable name is because you are setting $myRadio before the click event. $myRadio is set on document ready (before click event) and it gets the value of the checked radio option which at this moment is always 1.
Moving $myRadio inside a click handler should work. Why? Because now it gets the value of the radio (checked) as soon as the click function is called which is actually what you need.
$('#button').click(() => {
var $myRadio = $('[id^="option"]:checked');
// neither of these work
alert($('input[type=radio][name=options]:checked').val());
alert($myRadio.val());
});
fiddle here
For anyone else running into the same issue. Not wanting to call the radio button name when checking for its value, you can use filter -
var $myRadio = $('input[type=radio][name=options]');
$('#button').click(() => {
console.log($myRadio.filter(':checked').val());
}

"forceSelection:true" does not let clearing the field

When I set forceSelection:true for a combo, the user can not clear it after selectiong an option. Without adding a dummy empty choice, how can I let him to clear the field ?
I add a "clear" trigger to my comboboxes that need this support. Ultimately, you just need an action to hook onto in order to call clearValue().
Ext.create('Ext.form.field.ComboBox', {
...
trigger1Cls: 'x-form-clear-trigger',
trigger2Cls: 'x-form-arrow-trigger',
onTrigger1Click: function() {
this.clearValue();
}
});
Here's an http://www.sencha.com/forum/showthread.php?190886-How-to-reset-a-Combobox-or-Multiselect-to-no-values-selected
NOTE: You'll still need to do some CSS and create an image (probably) in order for the trigger image to show up.

Mvc Telerik grid cancel cell changes when input invalid

I am facing a small problem regarding input validation in mvc telerik grid.
I have it set to batch editting and I'm modifing the cells in an InCell mode.
Now whenever a user enters an invalid value in one of the inputs(Telerik's comboboxes/autocompletes), I'd like to display a message that
the entered value is iligal(this far I've managed on my own).
In addition to the message I'd like to revert the cell's value to it's previus value before
the user input.
So far I've tried:
grid.CancelCell(this);
$('#grid .t-grid-edit-cell input[type="text"]').value or innerText = prevVal;
The closest so far was e.newVal = e.oldVal, although it sometimes throws me a wierd exception in the jquery scripts or displays the combobox's drop down.
All the validatios and things I've tried are from the grid's client event OnSave()
It's same like what i searched before and I have solution for you.
On your OnSave() method has event like OnSave(e) and that 'e' carry all the elemnts and functions inside in my example after validation if not ok i can change that value to old value. Also you can use inspecter element log to look up what is inside 'e'
function onSave(e){
if(!validation)
{
///
}
else
{
e.cell.firstChild.value = "0"; // that is my edited cell
}
}

Categories

Resources