This is a migrated thread and some comments may be shown as answers.

Update date input with value today

2 Answers 124 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ignacio
Top achievements
Rank 1
Ignacio asked on 16 Feb 2017, 07:15 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Anton Dobrev
Telerik team
answered on 21 Feb 2017, 03:01 PM
@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
0
Ignacio
Top achievements
Rank 1
answered on 22 Feb 2017, 07:08 PM

Perfect.

Thank you !

Tags
General Discussions
Asked by
Ignacio
Top achievements
Rank 1
Answers by
Anton Dobrev
Telerik team
Ignacio
Top achievements
Rank 1
Share this question
or