jQWidgets Forums

jQuery UI Widgets Forums Editors DateTimeInput The formatString property cannot be used in the Knockout Integration

This topic contains 4 replies, has 3 voices, and was last updated by  Peter Stoev 10 years, 10 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author

  • ziyahan
    Participant

    Hi;
    We use Jqxwidget with Knockout together. but the formatString property cannot work. We cannot use this property.


    Peter Stoev
    Keymaster

    Hi ziyahan,

    We cannot find anything wrong with that property and how it works with KO. Please, find below a working sample:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title id="Description">Integration of jqxDateTimeInput with Knockout</title>
        <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="../../scripts/jquery-1.10.2.min.js"></script>
        <script type="text/javascript" src="../../scripts/json2.js"></script> 
        <script type="text/javascript" src="../../scripts/knockout-3.0.0.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
        <script type="text/javascript" src="../../scripts/demos.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxdatetimeinput.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxcalendar.js"></script>
        <script type="text/javascript" src="../../jqwidgets/globalization/globalize.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxknockout.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxcheckbox.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {   
                 var viewModel = function (date) {
                    this.date = ko.observable(date);
                    this.disabled = ko.observable(false);
                    this.displayDate = function () {
                        alert("Date: " + this.date());
                    }
                    this.setDate = function () {
                        var date = new Date();
                        date.setFullYear(2012, 11, 11);
                        this.date(date);
                    }
                };
    
                var date = new Date();
                date.setFullYear(2012, 10, 10);
                ko.applyBindings(new viewModel(date));
            });
        </script>
    </head>
    <body class='default'>
        <div id="input" data-bind="jqxDateTimeInput: {value: date, formatString: 'dddd MMM', disabled: disabled, width: '250px', height: '25'}">
        </div>
        <div style="margin-top: 5px; clear: both;">
            <input id="getButton" data-bind="click: displayDate, jqxButton: {}" type="button" value="Get Value" />
            <input id="setButton" data-bind="click: setDate, jqxButton: {}" type="button" value="Set Value" />
            <div data-bind="jqxCheckBox: {checked: disabled, width: '100px'}" style='margin-top: 5px;' id="checkBox">Disabled</div>
       </div>
    </body>
    </html>
    

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/


    ziyahan
    Participant

    Peter;
    Thanks for your reply. It has been done. It did not work because of that I wrote formatString wrongly like “DD-MM-YYYY”. Sorry.
    Thanks again.


    PRicardo
    Participant

    I’m using the version 3.0.4 and I have a problem setting a different ‘formatString’ parameter (MM/dd/yyyy).
    When I initialize the component with the value null – ko.observable(null) – and after I set some date, the component shows the date with the default format (formatString dd/MM/yyyy).
    When I initialize with use some value (new Date(), by example) the component works as expected!

    Thank you for some help.

    PRicardo


    Peter Stoev
    Keymaster

    Hi PRicardo,

    You can try the same with jQWidgets 3.4. In the version which you use “null” is invalid value for the DateTimeInput.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.