How to Change DTE_Field_ text color on client side validation

How to Change DTE_Field_ text color on client side validation

hotflohotflo Posts: 2Questions: 1Answers: 0

When the input value of the production_minutes column is lower than 0 i want to set the css color
of the input text to red. The next code block works, but is not dynamic:

dt_editor_executors.on( 'preSubmit', function ( e, o, action ) {
   if ( o.data.production_minutes < 0 ) {
      $("#DTE_Field_production_minutes").css('color', 'red');
      return false;
   }
});

In my datatable there are 3 colums where i want to attach this same validator.
How can i get the ID of the currently edited input field or how can is set the text-color
of the inputbox value dynamic. (without knowing the column name)

Note: i use the inline edit option of datatable editor.

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I would suggest using the field().node() method to get the container element: $( 'input', editor.field( 'production_minutes' ).node() ).css( ... );.

    Editor 1.4 is going to introduce a new input() method to make this kind of thing easier: editor.field( 'production_minutes' ).input().css( ... ).

    Given that you have the name of the field in o.data, you could loop over that and use it with the field().node() method.

    Allan

  • hotflohotflo Posts: 2Questions: 1Answers: 0

    Looping the fields in o.data is possible and works. But is there a solution to check the currently editted field. Or is there a kind of property "lastEdittedColumn".
    When thats possible i can make the validators more specific.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    But is there a solution to check the currently editted field

    Yes, in Editor 1.4 (note that this is currently in beta, so if you are using 1.3 or earlier you would need to update), there is the displayed() method which will tell you what fields are currently being edited. In the case of inline editing that will be whatever field is being edited only.

    Allan

This discussion has been closed.