2

I have used jQuery datatable CellEdit ( https://github.com/ejbeaty/CellEdit ) for table inline editor. This is a free lib. It's working awesome. This lib already provides required field validation.

For required validations, need to mention the column index inside of the columns array. Please see this code.

"allowNulls": {
    "columns": [],
    "errorClass": 'error'
}

For example, The table has 5 columns. if we need required field validation for the first 3 columns means, then need to use columns:[0,1,2].

The above mentioned code was inside of the table.MakeCellsEditable function. For more info please read the documentation ( https://github.com/ejbeaty/CellEdit/blob/master/README.md ).

This validation working well if we click confirm button without fill any values in the text box.

enter image description here

But, if I just leave it blank space means, the validations don't work. So, I can able to save the value in my DB with blank values.

So, I need to validate with blank space also.

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
jawahar N
  • 462
  • 2
  • 13
  • *able to save the value in my DB with blank values* When it is important, don't forget to back it up with server side validation. Never rely on client side validation only, as it is easy to bypass. – SOS May 02 '19 at 14:41
  • @Ageax Yeah sure. For my scenario, I don't need to submit the form. Before submitting the form, I need to validate my input. If we use server side, we couldn't able to achieve the above mentioned validation. I mean, need to set a border for that particular textbox. So, I choose this way. :) – jawahar N May 02 '19 at 15:16
  • Using client side validation to improve the UX is fine. However, if you're saving values to a database, that means you are submitting the form to the server. So you should *also* implement server side validation as a backup. Never rely on client side validation only :-) https://stackoverflow.com/questions/10460711/to-what-extend-should-i-rely-on-client-side-validation – SOS May 02 '19 at 15:26
  • Make sense. Thanks. I will do it server side validation also. :) – jawahar N May 02 '19 at 15:32

1 Answers1

1

I have analyzed their core JS file. In that file, they are getting cell value like var newValue = inputField.val();

This code is present on inside of the updateEditableCell function. So, instead of this code, We need to use below code,

var OrgValue = inputField.val();
var newValue = OrgValue.trim();

Now, we can able to validate if the textbox has blank space.

Thanks,

jawahar N
  • 462
  • 2
  • 13