Author Topic: Limit rows in multiline entries in pq grid  (Read 195 times)

gopigupta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 37
    • View Profile
Limit rows in multiline entries in pq grid
« on: December 13, 2023, 04:41:01 pm »
Hello,

I am using textarea in pqgrid to enter multi lines in a cell. I want to restrict users to add text only till 5 lines in text area. Is there any way to achieve this?

My code to have text area in cell:-


{
                title: "Field value",
                width: "300",
                dataIndx: "CFValue",
                dataType: "string",
                editable: true, nodrop: false, nodrag: false,
                editor: {
                    type: "textarea",
                    attr: "rows=5 cols=58",
                    style: "resize:both;",
                    appendTo: 'grid'
                },
                editModel: {
                    saveKey: '' //disable or set it to some other key code to free up use of Enter key for line breaks.
                },
                menuInHide: true, hidden: false,
                validations: [{ type: 'maxLen', value: 5000, msg: "Maximum length allowed is of 5000 chars long!" }],
                filter: { crules: [{ condition: 'contain' }], conditionList: ['range', 'contain'], labelIndx: 'CFValue' }, 
            },


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Limit rows in multiline entries in pq grid
« Reply #1 on: December 13, 2023, 11:08:27 pm »
Add init function to column.editor

Code: [Select]
init: function(ui){
ui.$editor.on('keydown', function(e){
if(e.keyCode == 13 && $(this).val().split("\n").length >= $(this).attr('rows')) {
return false;
}
});
}

gopigupta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Limit rows in multiline entries in pq grid
« Reply #2 on: December 14, 2023, 10:39:32 am »
Thank you for quick response