Update date input with value today

3 posts, 1 answers
  1. Ignacio
    Ignacio avatar
    19 posts
    Member since:
    Feb 2013

    Posted 16 Feb Link to this post

    Hello,
    I need to update date input with value today after change other input in the form.
    I don't know where is the problem. Don't works.

    Thanks.

    My code:

    ---html -------------------------------------------------

                    <li class="form-content-item">
                        <label id="fechaField" class="field km-listview-label field--datetime-local">
                            <span class="field__label" data-bind="text: strings.servicio.servicioModel.editableListForm.fecha.title" style="width: 40%;"></span>
                            <input id="fecha" data-bind="value: addFormData.fecha, enabled: false" type="datetime-local" style="width: 60%; font-weight: bold;">
                        </label>
                    </li>
                    <li class="form-content-item">
                        <label id="importeField" class="field km-listview-label field--number">
                            <span class="field__label" data-bind="text: strings.servicio.servicioModel.editableListForm.importe.title" style="width: 40%;"></span>
                            <input id="importe" data-bind="value: addFormData.importe, events: { change: servicioModel.pagar }" type="number" style="width: 60%; font-     weight: bold; font-size: 1.5em; padding-top: 0.5em; visibility: initial; ">
                        </label>
                    </li>
    ---js-------------------------------------------------          

                pagar: function() {
                    var i = $('#importe').val();
                    var p = $('#peaje').val();
                    var g = parseFloat(Number(i) + Number(p));
                    g = kendo.toString(parseFloat( g  ), '#.##')
                    $('#pagado').val(g).change();
                    var currDay = dFec();
                    currDay = kendo.toString(kendo.parseDate(currDay), 'dd/MM/yyyy HH:mm:ss');
                    $('#fecha').val(currDay);
                }, 

        function dFec() {
        var d = new Date,
            dformat = [d.getDate(),
                    d.getMonth()+1,
                    d.getFullYear()].join('/')+' '+
                    [d.getHours(),
                    d.getMinutes(),
                    d.getSeconds()].join(':');
            return d;           
        } 

  2. Answer
    Anton Dobrev
    Admin
    Anton Dobrev avatar
    599 posts

    Posted 21 Feb Link to this post

    @Ignacio

    It appears that the input with Id fecha is not in the markup, perhaps, it this is the case, otherwise it should be working as in this example (just select from the Some text field).

    Also, it may be better to use the MVVM properties instead of searching the element with jQuery as in this example (see the MVVM date).

    I hope this helps.

    Regards,
    Anton Dobrev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Ignacio
    Ignacio avatar
    19 posts
    Member since:
    Feb 2013

    Posted 22 Feb in reply to Anton Dobrev Link to this post

    Perfect.

    Thank you !

Back to Top