I have a group field with two subfields:
1) "Select" field
2) "Text" Field
Let's imagine select have the followings options:
I wan't to save in the database "select" and "text" value group only if "text" value is not empty. How can achieve that?
I think you can use the extension MB Conditional Logic to show the
select field when the
text field is not empty. Then mark them as Required.
Get more details on the documentation https://docs.metabox.io/extensions/meta-box-conditional-logic/
Sorry but this doesn't fit my needs.
In case the user doesn't touch the select, I don't want to save anything in the database. Now if a user doesn't select anything in the database the default select value is saved and the text field not.
So you can show the
text field only the users select an option and mark
required for the text field. Is that easier?
Here is the sample code
But I don't want the select to be required. In my project, the user could not select anything, the same way he can leave a text field empty.
I would suggest for Meta Box developers: like when you leave an empty "text field" it is not saved in the database, It could be good that when the user doesn't touch the "select field" it is not saved as well (unless you have filled a Default Value). How is developed now, a default value is saved, regardless of whether we have put a default value for the select or not.
On my sample code above, there is no
required setting of the
select field. You just need to set this to the
Regarding the standard (Default) value, you can use the setting
placeholder instead to prevent save the default value.