Deleting a 0 in numeric field doesn't cause in-line editor to update

Deleting a 0 in numeric field doesn't cause in-line editor to update

capeckcapeck Posts: 54Questions: 13Answers: 1

I have an inline editor set up with multiple numeric fields. If the record starts with a 0 in a field and I delete the 0 (wanting to make it null), there is not an update. If I update the field to something other than 0, like 1, then delete the 1 , the field will become a null. Here is the field setting:

    Field::inst( 'am_wx.curwindspd' )
        
        ->setFormatter( Format::ifEmpty( null ) )

If the field starts as something other than 0, I clear it out and can see that the PHP server script is called to update and the field stays as a null. If the field starts as 0, I clear it out, and the PHP server script is never called.

I'm sorry I can't post to a test example right now.

Thanks in advance.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    Hi,

    I've just tried to reproduce the issue in this example. What I did was:

    1. Edit Salary in the first row to be 0
    2. Submit that
    3. Edit that cell again - this time deleting the input so it is empty
    4. Submit again
    5. I'm seeing a second Ajax request being made.

    I'm wondering if you might have a Javascript check somewhere that is blocking the submit? I think I would need a test case showing the issue to be able to help resolve this one I'm afraid.

    Allan

  • capeckcapeck Posts: 54Questions: 13Answers: 1

    Thanks for looking at this. I'll explore further and try to get a test case posted soon.

  • capeckcapeck Posts: 54Questions: 13Answers: 1

    Alan,
    I've tried to put in some breaks in editor to see if I can figure anything out. Changing a 0 to blank , when it gets to deepCompare, console shows:

    o1
    ''
    

    and

    o2
    0
    

    and

    o1 == o2
    true
    

    So it never triggers the edit event.
    I am using version 2.0.5 installed from webpack.

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    Interesting - thanks for digging into that.

    I'm trying to think about how I can reproduce that locally. Can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is. That will let me see the data you are using.

    Thanks,
    Allan

  • capeckcapeck Posts: 54Questions: 13Answers: 1

    I am getting an error on the debugger. This is a webpack build and normally jquery is in the build js file, so I had to include jQuery again so that debugger would run (if that makes sense).

    Uncaught TypeError: Cannot read properties of undefined (reading 'length')
        at Object.default_1 [as info] (debug.datatables.net/bookmarklet/DT_Debug.js?rand=1643992127365:460:25)
        at HTMLDivElement.<anonymous> (debug.datatables.net/bookmarklet/DT_Debug.js?rand=1643992127365:97:25)
        at HTMLDivElement.dispatch (jquery-3.6.0.min.js:2:43064)
        at HTMLDivElement.v.handle (jquery-3.6.0.min.js:2:41048)
    

    and

    Uncaught TypeError: Cannot read properties of undefined (reading 'sVersion')
        at gatherData (debug.datatables.net/bookmarklet/DT_Debug.js?rand=1643992127365:512:36)
        at debug.datatables.net/bookmarklet/DT_Debug.js?rand=1643992127365:497:13
    

    I am suspicious that I have numeric values in my json and it is comparing a numeric 0 to blank string and coming out equal. An example is curwindspd in the data that has a 0 but should be blanked out. Here is some sample json data i use:

    {"data":[{"DT_RowId":"row_168250","am_wx":{"id":168250,"curtemp":8,"maxtemp":8,"mintemp":-5,"curwindspd":null,"curwinddir":null,"avewindspd":null,"avewinddir":null,"ttlwindmiles":null,"hhrwindtime":null,"hhrwindspd":null,"hhrwinddir":null,"maxgust":null,"newsnow":null,"swe":null,"depth":null,"density":null,"rh":null,"ttlsnowfall":null,"forecast_id":11957,"station_id":2},"station":{"display_name":"RBowl 9,580","display_order":2,"precip":true,"wind":false,"temps":true,"rh":false}},{"DT_RowId":"row_168251","am_wx":{"id":168251,"curtemp":null,"maxtemp":null,"mintemp":null,"curwindspd":0,"curwinddir":0,"avewindspd":2,"avewinddir":131,"ttlwindmiles":40,"hhrwindtime":"18:00","hhrwindspd":6,"hhrwinddir":179,"maxgust":12,"newsnow":null,"swe":null,"depth":null,"density":null,"rh":null,"ttlsnowfall":null,"forecast_id":11957,"station_id":20},"station":{"display_name":"Buff Bowl 7970","display_order":7,"precip":false,"wind":true,"temps":false,"rh":false}},{"DT_RowId":"row_168231","am_wx":{"id":168231,"curtemp":8,"maxtemp":8,"mintemp":-6,"curwindspd":null,"curwinddir":null,"avewindspd":null,"avewinddir":null,"ttlwindmiles":null,"hhrwindtime":null,"hhrwindspd":null,"hhrwinddir":null,"maxgust":null,"newsnow":null,"swe":null,"depth":null,"density":null,"rh":84,"ttlsnowfall":null,"forecast_id":11957,"station_id":3},"station":{"display_name":"Raymer 9,360","display_order":3,"precip":true,"wind":false,"temps":true,"rh":true}}]}
    

    Thanks.

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Answer ✓

    Ah - yes, I think you are right. I need to have a little thing about that. We can't use strict typing there, because when a number value is put an input element and then read back, it will come back as a string. Possibly I need to add some extra checks for specific falsy cases in there. Many thanks for the data and insight - I'll get back to you on Monday about this.

    Allan

  • capeckcapeck Posts: 54Questions: 13Answers: 1

    Thanks so much!

  • capeckcapeck Posts: 54Questions: 13Answers: 1

    Any chance you've had a chance to look at this? I am not quite sure how to know if this is still an active issue. Thanks.

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    Apologies - yes, this is still active - I haven't had a chance yet to dig into this. Will try to make sure I do so tomorrow and get back to you.

    Allan

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    I've been thinking about this a bit more and I think fields.getFormatter is going to be the solution - e.g. add this to the field type that is causing problems because it is being converted to a string:

    getFormatter: function (val) {
      return parseFloat(val);
    }
    

    That will convert the string value to a number whenever the value is read.

    Regards,
    Allan

  • capeckcapeck Posts: 54Questions: 13Answers: 1

    Hi,
    Thanks for looking at this, but It doesn't seem to be fixing the problem. The json ajax data is a numeric, so converting to a value doesn't change it. However, I did try this:

    return strval($val)
    

    and it seems to work. Would that make sense to you?

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Answer ✓

    Yes - that makes sense. It is basically approaching it from the other side. I'm surprised the client-side formatter didn't do the job though - I will look into that. Thanks!

    Allan

Sign In or Register to comment.