Author Topic: error when cell value is cleared or only spaces are entered  (Read 477 times)

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 169
    • View Profile
Hello,

I'm using ParamQuery Pro v10.1.0

I'm encountering a bug when editing a cell with `dataType: "string"` — even though the column is not a date field, the following error occurs **after I delete the cell content** using Backspace or **enter only spaces**, then press **Tab** to move to another cell.

Here is the console error:

Code: [Select]
Uncaught TypeError: can't access property 0, f is null
    at parseDateFromFmt (pqgrid.dev.js:1883)
    at parseDate (pqgrid.dev.js:1899)
    at deformat (pqgrid.dev.js:2835)
    at getEditCellData (pqgrid.dev.js:3487)
    at saveEditCell (pqgrid.dev.js:3044)
    at saveAndMove (pqgrid.dev.js:4354)


### Reproduction Steps:

1. The column has `dataType: "string"`, no special `editor.format` or custom parse logic.
2. Enter any value in the cell, then delete it using Backspace and press Tab.
3. OR enter only space characters (`"   "`), then press Tab.
4. This throws the error above.

---

### What I Tried:

I attempted to sanitize the value using `beforeCellSave`:

Code: [Select]
beforeCellSave: function (evt, ui) {
  if (typeof ui.newVal === 'string' && ui.newVal.trim() === '') {
    ui.newVal = null;
  }
}

Unfortunately, this **did not fix** the issue.
The error still occurs, and strangely, `parseDateFromFmt()` is triggered even though the column is not a date field.

---

### What I Need Help With:

* Why is `parseDateFromFmt` called at all for a `dataType: "string"` column?
* What’s the proper way to prevent this error when the cell is cleared or contains only whitespace?
* Is this a known issue or do I need to override some internal formatter?

Any guidance or recommended workaround would be greatly appreciated.

**Can I record a short video showing the issue and send it to you via email?**
Thanks in advance.



colmodel sampla
Code: [Select]
,{title:'Sample',dataIndx:'vdata',dataType:'string',minWidth:24,width: 200,cls:'',clsHead:'',align:'',halign:'center',aciklama:'vdata',hidden:false,editable:true
,filter: { crules: [{ condition:'contain'}],menuIcon:false}
}
« Last Edit: July 21, 2025, 08:26:20 pm by omerix »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6415
    • View Profile
Re: error when cell value is cleared or only spaces are entered
« Reply #1 on: July 21, 2025, 09:30:52 pm »
Have you specified fmtDateEdit option in your grid initialization object?

https://paramquery.com/pro/api#option-fmtDateEdit

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 169
    • View Profile
Re: error when cell value is cleared or only spaces are entered
« Reply #2 on: July 21, 2025, 09:39:21 pm »
Yes, I was using fmtDate. Once I removed it as you suggested, it worked perfectly — you're awesome, thank you! 🙌

I had been including it by default in all my grids to ensure consistent date formatting.

What would be the recommended approach now to apply a standard date format across all grids going forward?

Code: [Select]
,fmtDate:'dd/mm/yyyy',fmtDateEdit:'dd/mm/yyyy',fmtDateFilter:'dd/mm/yyyy'


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6415
    • View Profile
Re: error when cell value is cleared or only spaces are entered
« Reply #3 on: July 21, 2025, 11:29:31 pm »
Your code is fine, please use this patch before initialization of grids to fix the issue:

Code: [Select]
(function(){
let _p = pq.parseDate;
pq.parseDate = function(fval, ...args) {
if (!fval || typeof fval != 'string' || fval.trim() == ''){
return '';
}
return _p.apply(this, arguments);
}
})();