Migx TV to store default value of "0" is not setting


If i set a default value of zero for a field it is not applying, is a standard text field

Step to reproduce

Create migx field, set default value to zero, Now create a new migx item in the CMS and the 0 value will not be present, the text field will be blank.

Observed behavior

See above

Expected behavior

It should store the 0 string, anything > 0 seems to work fine


Mysql 5.6
php 7.4 - Apache
modx 2.8.1
migx 2.12.0

As a workaround you could create a new TV with a “Default Value” of 0 and then use this TV in your MIGX-configuration (field Input TV). It should work this way.

Cheers for that, unfortunately i have maybe 10 or so fields that i want to pre populate with a zero (its for an externally accessed API) and i would rather not create 10 separate TVs just to be able to set a value to 0 :frowning:

but thanks for that, atleast i know it is possible through another route. If anyone else has another alternative way (maybe modifying how migx handles zeros in its component or something) then I’m all ears.

Do you use MIGX as a TV or do you use MIGXdb (to store the data in a custom tabe)?

In this instance it is using migx as a tv, but i also have other areas where i am using it with migxDB with custom tables, i have not checked if that stores zero’s yet as i haven’t had the need for it to store one just yet,

maybe you can create a 0 value at output-time, when the value is empty

With MIGXdb you’d have more options (default values in the database, overriding the save()-function of your class that extends xPDOSimpleObject, maybe using an aftersave-hook snippet).

With MIGX as a TV you could write a plugin that runs on the event “OnDocFormSave”, but it’s probably easier to set the value at output-time like Bruno suggested.

If you don’t mind altering source files, you could try changing this line


if (!empty($field['default']) || ($field['default'] === '0')) {

to account for 0 as the default value.