DataTables / Editor-PHP

PHP server-side libraries for Editor
Other
35 stars 22 forks source link

Format::ifEmpty() should do what it describes #12

Closed SlenderPaul closed 2 years ago

SlenderPaul commented 2 years ago

Either the check should be Like this or the comment describing the function should state that only an empty string will be formatted.

AllanJard commented 2 years ago

Many thanks for this! I'm not sure about '0' being treated as empty though. The others are okay, but that seems like a valid value to me.

SlenderPaul commented 2 years ago

You are right. PHP is pretty weird in that case. Maybe just test forisset() and empty string '' instead?

SlenderPaul commented 2 years ago

Btw I'm kinda new to GitHub. Do I just close this Pull request? Would you value a different one where '0' is not evaluated as empty?

AllanJard commented 2 years ago

In Editor, if the value isn't set then it wouldn't actually get that far. It doesn't process fields which haven't been sent to the server (although they can be marked as required).

Was there a specific issue that you were trying to resolve with this change?

SlenderPaul commented 2 years ago

Yes there was. Tho its problably very specific indeed. I've created a custom Editor Plugin Field which lets me create, edit, and delete rows from a joined table. On submit its returned value is an array with data for each row. Due to the rows containing a checkbox, some of the values would just not be set, but I still wanted to insert a default value into the Database in that case. Anyways I kinda read the comment of Format::ifEmty() and thought that it would fit perfectly for this and then had to seach a little to figure out why it wasn't working. If you don't want to change the functionality of the function, the comment of it should definetly be changed. It was pretty misleading to read that it outputs a default if a value is null but its not doing that at all.

SlenderPaul commented 2 years ago

Oh wait Im just realizing that I might have read the comment the wrong way??? I thought the Example `(e.g. null, 0, 'Not set',

SlenderPaul commented 2 years ago

Ok I'm just realizing now what is actualy happening here. You are completely right. The formater doesn't even get called if there is no value for the field. It's just so happens to work anyway in my case, because the Mjoin deletes all the rows and then reinserts them. So the column that isn't set just gets its default from the Database. I thought It would update the row and I had to change the value for the column myself. I can't quite remember why I thought changing the Formatter Function helped me.

AllanJard commented 2 years ago

Hi - many thanks for the update. Good to hear you've got this working now. Yes, the examples were meant to be values that could be written to the database in place of the empty string.