I already use the onBeforeEditStop event. The problem is that i need an event before the value is change to verify that a valid input was entered. If you type in a unvalid option or leave the text field empty, the value is automatically set to the first option of the suggest/combo. I need it to keep is original/old value if an unvalid input was entered. When the onBeforeEditStop or onValueSuggest is triggered the value and old state is already set to the first option, so i don’t know if the user selected option 1 or it was automatically set becasue of an invalid input.
In your snippet, click to open the combo/suggest popup. In the text field clear all text or type in an unvalid value and press the enter key. The value of new is automatcally set to the first option, which is 1 in your example. I need it to keep it’s old value if an empty or invalid input was entered.
Hi Intregral. I check the rules properties, but it seems i get the same result. The original entered invalid value from the combo/suggest is already set to value of the first option when the rule is triggered. I think i need to handle this on the combo/suggest level, preferably on the onChange event.
<code class="js">
rules: {
"assignedtx_combo_value": function (value: any) {
console.log("value is: " + value); // returns option 1, not the original input
//return value > 0
}
`
<code class="js">
on: {
"onChange": (newv: string, oldv: string) => {
// Check if the entered input is a valid value.
let input = Data.txComboCollection.find((item) => item.value === newv);
// Prevent the change if the entered value is not valid.
if (input === undefined) {
}
}
}
The combo editor in Datatable is not a UI Combo in fact. There’s an HTML input with a suggest list linked to it, so there can’t be any onChange event.
You can still make use of the onBeforeEditStop and rewrite the old value as:
onBeforeEditStop:function(values, editor){
if(editor.column == "assignedtx_combo_value"){
//if value is not correct or empty
if(!values.value || !editor.getInputNode().value)
// delay the operation intil editing is completed
webix.delay(function(){
this.updateItem(editor.row, {[editor.column]: values.old})},
this);
}
}
Your snippets work if the text field is empty, but it still reverts to option 1 if you enter an invalid input.
Open the combo
Enter a invalid option like abc and press enter.
The cell value is set to the value of option 1, not the old value.
Integral: The state.value is already set to the value of option 1 by the time the onBeforeEditStop is triggered. So i have no way of knowing if state.value is set to the value of option 1 purposfully by a user and therefor valid, or if it was set by the combo due to an invalid input and the old value should be preserved.
It this functionality is not possible. Maybe there is a way to keep the column type as normal text field and invoke a popup anchored to the cell with a filterable list of options. You can then selected a new value and then be able to validate the input before you change the cell value programmatically.