[Migx] migxdb formtabs show or hide depending if inserting item or updating item

Summary

I am creating a Migxdb with nested migxdb and this working perfectly. But I am trying to find a way to hide a migxdb tab when inserting item, but I am not able to find anything related to this on the documentation

Step to reproduce

This is my config file (summarized):

{
“formtabs”:[
{
“MIGX_id”:9,
“caption”:“Elemens”,
“print_before_tabs”:“0”,
“fields”:[
{
“MIGX_id”:39,
“field”:“name”,
“caption”:“Title”,
“description”:“Element title”,
“description_is_code”:“0”,
“inputTV”:“”,
“inputTVtype”:“text”,
“validation”:“required”,
“configs”:“”,
“restrictive_condition”:“”,
“display”:“”,
“sourceFrom”:“config”,
“sources”:“”,
“inputOptionValues”:“”,
“default”:“”,
“useDefaultIfEmpty”:“0”,
“pos”:1
},
{
“MIGX_id”:49,
“field”:“lexicon_key”,
“caption”:“Lexicon Key”,
“description”:“Lexicon Key”,
“description_is_code”:“0”,
“inputTV”:“”,
“inputTVtype”:“text”,
“validation”:“required”,
“configs”:“”,
“restrictive_condition”:“”,
“display”:“”,
“sourceFrom”:“config”,
“sources”:“”,
“inputOptionValues”:“”,
“default”:“”,
“useDefaultIfEmpty”:“0”,
“pos”:1
},
{
“MIGX_id”:40,
“field”:“first_year”,
“caption”:“First year”,
“description”:“First Year”,
“description_is_code”:“0”,
“inputTV”:“”,
“inputTVtype”:“”,
“validation”:“required”,
“configs”:“”,
“restrictive_condition”:“”,
“display”:“”,
“sourceFrom”:“config”,
“sources”:“”,
“inputOptionValues”:“”,
“default”:“”,
“useDefaultIfEmpty”:“2000”,
“pos”:2
},
{
“MIGX_id”:41,
“field”:“last_year”,
“caption”:“Last Year”,
“description”:“Last Year”,
“description_is_code”:“0”,
“inputTV”:“”,
“inputTVtype”:“”,
“validation”:“required”,
“configs”:“”,
“restrictive_condition”:“”,
“display”:“”,
“sourceFrom”:“config”,
“sources”:“”,
“inputOptionValues”:“”,
“default”:“”,
“useDefaultIfEmpty”:“2100”,
“pos”:3
}
],
“pos”:1
},
{
“MIGX_id”:2,
“caption”:“Dates”,
“print_before_tabs”:“0”,
“fields”:[
{
“MIGX_id”:51,
“field”:“Dates”,
“caption”:“Dates”,
“description”:“Get all dates for this Element”,
“description_is_code”:“0”,
“inputTV”:“”,
“inputTVtype”:“migxdb”,
“configs”:“elements_dates”,
“sourceFrom”:“config”,
“sources”:“”,
“inputOptionValues”:“”,
“default”:“”
}
],
“pos”:2
}
],
}

Observed behavior

When inserting an element, the “Dates” tab is also shown. This means that someone can insert dates for an element that is not yet existing in the DB and, as consequence, the id of the element will not be automatically added to the “elements_dates” table having the element id.

Expected behavior

How can I hide a tab when creating an element, and show it when editing an element?

Environment

Modx 2.7.1 with Migx 2.12.0-pl

Thanks in advance.

this is, what restrictive_condition is for
you can place a snippet, which returns 1 when specific values are posted in the request
check the request in your dev-console, what is send at new and updated items

1 Like

Many thanks for the quick answer Bruno.
I will give it a try and share the outcome.

Cheers

Hi Bruno,

Many thanks again for the tip.
It was the lead that I was missing so I could end up with what I was looking for.

This is what I did (Sharing is caring :smiley:):

  • Inspected the connector.php request,
  • Found “isnew” parameter,
  • On the snippet side, it was just a matter of reading it and return “1” or “” to do the trick.

Then just added this on the migx config side:

“restrictive_condition”:“[[MigxCheckIfIsNewItem]]”,

Spot on!

Cheers

thanks for reporting!
There is also a snippet, shipped with MIGX, which I forgot about:

Ah! This is handy. It will be the solution itself.
Many thanks for this awesome extra.

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.