Is it possible to force refresh of the view?

2 posts, 0 answers
  1. Boris
    Boris avatar
    14 posts
    Member since:
    Aug 2015

    Posted 20 Jun Link to this post


    I have an input element. It displays duration of an activity, so valid values are only numbers. When user types in an incorrect value, I show alert and then set the input value to the last correct input value.

    Since I always want to display the value with one decimal number, I have bound the input to the function, which performs the formatting.

    This is the part of the view:

    <input data-bind="value: durationString" />

    This is the part of the viewModel:

    01.duration: 0;
    03.//Converts string from the input to duration number and vice versa. Checks whether the string is a permitted number.
    04.durationString: function (value) {
    05.    if (value !== undefined) {
    06.        var valueAsNumber = checkCorrectItemDuration(value);
    07.        if (valueAsNumber !== -1) {
    08.            this.set('duration', valueAsNumber); //new value is correct, set it
    09.        }
    10.        else {
    11.            this.set('duration', this.get('duration')); //new value is incorrect, set the previous value
    12.        }
    13.    }
    14.    else {
    15.        return kendo.toString(this.get('duration'), 'n1');
    16.    }

    The problem is on the line 11. This line is executed when the value typed in the input is incorrect. I set the duration property to the same value as the value which it already has. I thought that this would force the input element to display the value from the duration property. But since the old and the new value of the duration property is the same, the input is not forced to refresh itself and so it still displays the incorrect value.

    So, is it possible to force the input to display the correct value from the viewmodel?

    Thanks for answers,


  2. Petyo
    Petyo avatar
    2437 posts

    Posted 22 Jun Link to this post


    the logic you try to implement seems more suitable for another approach. Prevention of the input change event would do exactly what you want - revert the element value to its previous state.

    Apart from that, "refresh" of the view is not supported. 

    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
Back to Top