MIGXdb config to limit characters in field of type textarea

  • MODX Revolution 2.8.5-pl
  • MIGX 3.0.2-beta1

Under my current configuration there is a database field named introtext with precision 255.

<field key="introtext" dbtype="varchar" precision="255" phptype="string" null="false" default="" />

When entering data via a MIGX CMP the following error presents in a popup lightwindow quip.thread_err_save.

The MODX Error Log clearly shows this is because the data entered is longer than 255 characters.

Data too long for column 'introtext' at row 1

Can anyone advise how to configure MIGX to alert the user to the length error as MODX would do for a TV of the same type?

I tried setting the Configs value for the introtext field to {"maxLength":"255"} but this has no effect.

On the Docs for TV Input Types there are notes for all input option names (for use in migx options-json) eg.

{
    "allowBlank": "true",
    "maxLength": "",
    "minLength": "",
    "regex": "",
    "regexText": ""
}

But I don’t see a field named options-json in the MIGX config. What did I miss?

MIGX config is below

{
  "formtabs":[
    {
      "MIGX_id":8,
      "caption":"Review caption",
      "print_before_tabs":"0",
      "fields":[
        {
          "MIGX_id":32,
          "field":"title",
          "caption":"title",
          "pos":1
        },
        {
          "MIGX_id":33,
          "field":"introtext",
          "caption":"introtext",
          "description":"",
          "description_is_code":"0",
          "inputTV":"",
          "inputTVtype":"textarea",
          "validation":"",
          "configs":{
            "maxLength":155
          },
          "restrictive_condition":"",
          "display":"",
          "sourceFrom":"config",
          "sources":"",
          "inputOptionValues":"",
          "default":"",
          "useDefaultIfEmpty":"0",
          "pos":2
        },
        {
          "MIGX_id":34,
          "field":"customer_name",
          "caption":"customer_name",
          "pos":3
        }
      ],
      "pos":1
    }
  ],
  "contextmenus":"update||duplicate||remove",
  "actionbuttons":"addItem",
  "columnbuttons":"",
  "filters":"",
  "extended":{
    "migx_add":"",
    "disable_add_item":"",
    "add_items_directly":1,
    "formcaption":"VenueReviewItem form caption",
    "update_win_title":"VenueReviewItem window title",
    "win_id":"VenueReviewItem",
    "maxRecords":"",
    "addNewItemAt":"top",
    "media_source_id":"",
    "multiple_formtabs":"",
    "multiple_formtabs_label":"",
    "multiple_formtabs_field":"",
    "multiple_formtabs_optionstext":"",
    "multiple_formtabs_optionsvalue":"",
    "actionbuttonsperrow":4,
    "winbuttonslist":"",
    "extrahandlers":"this.handleColumnSwitch||this.publishObject||this.unpublishObject",
    "filtersperrow":4,
    "packageName":"venue",
    "classname":"VenueReviewItem",
    "task":"",
    "getlistsort":"pos",
    "getlistsortdir":"asc",
    "sortconfig":"",
    "gridpagesize":"",
    "use_custom_prefix":"0",
    "prefix":"",
    "grid":"dragdrop",
    "gridload_mode":2,
    "check_resid":1,
    "check_resid_TV":"",
    "join_alias":"VenueReviewGroup",
    "has_jointable":"yes",
    "getlistwhere":"",
    "joins":"",
    "hooksnippets":"",
    "cmpmaincaption":"VenueReviewItem main caption",
    "cmptabcaption":"VenueReviewItem tab caption",
    "cmptabdescription":"VenueReviewItem tab description",
    "cmptabcontroller":"",
    "winbuttons":"",
    "onsubmitsuccess":"",
    "submitparams":""
  },
  "permissions":{
    "apiaccess":"",
    "view":"",
    "list":"",
    "save":"",
    "create":"",
    "remove":"",
    "delete":"",
    "publish":"",
    "unpublish":"",
    "viewdeleted":"",
    "viewunpublished":""
  },
  "fieldpermissions":"",
  "columns":[
    {
      "MIGX_id":6,
      "header":"id",
      "dataIndex":"id",
      "width":15,
      "sortable":true,
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":""
    },
    {
      "MIGX_id":2,
      "header":"title",
      "dataIndex":"title",
      "width":"",
      "sortable":true,
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":"this.textEditor"
    },
    {
      "MIGX_id":3,
      "header":"introtext",
      "dataIndex":"introtext",
      "width":"",
      "sortable":true,
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":"this.textEditor"
    },
    {
      "MIGX_id":4,
      "header":"customer_name",
      "dataIndex":"customer_name",
      "width":"",
      "sortable":true,
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":"this.textEditor"
    },
    {
      "MIGX_id":5,
      "header":"published",
      "dataIndex":"published",
      "width":25,
      "sortable":true,
      "show_in_grid":1,
      "customrenderer":"",
      "renderer":"this.renderClickCrossTick",
      "clickaction":"",
      "selectorconfig":"",
      "renderchunktpl":"",
      "renderoptions":"",
      "editor":""
    }
  ],
  "category":""
}

You use the input field “Configs” to set the input-properties for the fields in the update-window.


Alternatively, you could maybe use the “Validation” field, and then create a validation-hook-snippet or update the code in the update-processor.

Thanks.

I didn’t get this to work yet though. Going by your note on the Configs field, I understand the value I tried earlier should have restricted the length of the introtext field to 255 characters {"maxLength":"255"} ?

The MIGX config in the post linked below uses the following, which follows the format from the Docs for TV Input Types as noted above. I tried this but the error quip.thread_err_save remains.

"configs":{
	"allowBlank":true,
	"maxLength":255,
	"minLength":0,
	"regex":"",
	"regexText":""
},

I’ll come back to this later with fresh eyes.

Thanks

The MODX documentation lists the “maxLength” option only for the field type Text and not for type Textarea.
In a MODX TV of type Textarea, there also doesn’t seem to be an input-option to restrict the length.

I guess you have to use the approach with the “Validation” field.
If you already have a custom update-processor, you can add a new validation-option here in the code:

You’re absolutely right, I need to slow down for a second and try to avoid the schoolboy errors.

There is a custom update-processor in place already. I’ll get a look at adding a custom validation-option in the morning.

Thanks again.