| Q | A |
| --- | --- |
| Bug? | yes |
| New Feature? | no |
| Sulu Version | 1.3.0 |
| Browser Version | Chrome 53.0.2785.116 m (64-bit) on Windows 10 |
Neither mandatory="true" nor minOccurs="1" attributes on contact selection content type in a page template doesn't prevent user from saving the page when no contacts has been selected.
Either mandatory="true" or minOccurs="1" attributes on contact selection content type in a page template should ensure that at least 1 contact has been selected and prevent user from saving the page if the latter condition hasn't been fulfilled.
Open any page template and add new field of type contact:
<property name="client" type="contact" mandatory="true" minOccurs="1">
<meta>
<title lang="en">Client</title>
</meta>
<params>
<param name="contact" value="false"/>
<param name="account" value="true"/>
</params>
</property>
In the CMS, open any page which uses that template. Make sure the contact field is empty (no contacts are selected) and hit Save button. In such scenario, mandatory field has to ensure at least 1 contact has been selected and prevent Save action from occurring if not. It doesn't though.
the usage of minOccurs (also maxOccurs) would be nice and i agree your thoughts about that. but with the mandatory i have a little problem because are multiple selected fields also valid (if mandatory) if no item is selected? mandatory was introduced originally to ensure that the value is not null and a empty array is also not null. /cc @chirimoya @danrot what do you think?
IMO the mandatory attribute in the XML file has a more semantical meaning than just not null. If there is no contact assigned I would consider it empty, making the mandatory validation fail. Otherwise it has really no meaning when added on these fields.
ok that seems to be an argument this should then also be implemented in following selections:
There seems to be the same problem for the single internal link, see https://github.com/sulu/sulu/issues/3249
I personally think we should get rid of general max and min occurs attributes on the property tag. And the field types which support such kind of things should have a param for it e.g.:
<property name="pages" type="page_selection">
<params>
<param name="min" value="3"/>
<param name="max" value="3"/>
<params>
</property>
Parts of that have been fixed in #5640, so media_selection and single_media_selection will now consider the mandatory flag correctly :slightly_smiling_face:
Most helpful comment
I personally think we should get rid of general max and min occurs attributes on the property tag. And the field types which support such kind of things should have a param for it e.g.: