Date Input Control

Date Input Control

notyou61notyou61 Posts: 21Questions: 8Answers: 0

I have the following Editor Field code:

                    // Termination Date
                    {
                        label:      "Termination Date:",
                        name:       "userNotVaildDate",
                        type:       "date",
                        def:        function () { return new Date(); },
                        dateFormat: $.datepicker.ISO_8601
                    }

The datepicker field provides the current date when the database value for the 'userNotVaildDate' field is null; I need it to provide the null value. Any help is appreciated.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,529Questions: 1Answers: 10,473 Site admin

    Hi,

    Interesting one. The def function is only run if the value is undefined. null values should not trigger the default value to be used.

    In Editor, you will find the following code:

            var val = field.valFromData( data );
            field.set( val !== undefined ? val : field.def() );
    

    Could you add console.log( field.name(), val ); just after those lines to check what the value is (i.e. if it is undefined). Could you also try using the DataTables nightly, if you aren't already: http://datatables.net/download/#DataTables ).

    Thanks,
    Allan

  • notyou61notyou61 Posts: 21Questions: 8Answers: 0

    The value in the database was not null instead was '0000-00-00'. I made them a null value by default and the datepicker field provides a blank field. It does however revert back to the '0000-00-00' value when saving the null from the form using the code. I am using PHP 5.2.0, the field is a DATE type and the default value is null.

    I tried the console log request as follows:

    $.each( fields, function ( name, field ) {
        var val = field.valFromData( data );
        field.set( val !== undefined ? val : field.def() );
        console.log( field.name(), val );
    } );
    

    No value appeared in the Firebug console.

    Thanks for any help.

  • allanallan Posts: 63,529Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Ah, if you re using PHP 5.2 then you must also be using the old (and now unsupported) PHP libraries for Editor I guess? Or have you got your own custom libraries. Either way, I would suggest that what needs to be done is if the value come the client-side is an empty string (I'm presuming it is?) then set the value as null into the database. A setFormatter could be used to do that in the Editor PHP libraries (although I'm not sure about the old 5.2 compatible libraries).

    Allan

  • notyou61notyou61 Posts: 21Questions: 8Answers: 0

    I found an easy solution by changing the database field to varchar data type, working so far.

This discussion has been closed.