Content blocks bug? No remove item icon when maxitems=1 and required=true

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Content blocks bug? No remove item icon when maxitems=1 and required=true

Niels van Kampenhout-2
Hello list,

I have a small issue with the Content Blocks addon [1]. The use case
is as follows:

I have two compound types, let's call them A and B.
In a document type, I have a "content blocks" field that allows the
user to add either an A or a B. This works well.
The content blocks field has required set to true, and maxitems=1.
'Required' works in that a newly created document can't be saved until
either A or B has been added.
'Maxitems=1' works in that once either an A or a B has been added,
it's not possible to add more.
However, once an A or a B has been added, it can't be removed: the
usual 'X' icon is not displayed. This means the user can't remove e.g.
an A and replace it with a B.
Setting required to false on the content blocks field brings back the
'X' but obviously now the user can save without any A or B added.

This looks like a bug: I see no reason not to have the 'X' (remove
item) option when the field is required. Instead, the validation of
the document should fail on saving if there are 0 items in the content
blocks field.

WDYT?

Thanks,
Niels

[1] http://content-blocks.forge.onehippo.org/
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Content blocks bug? No remove item icon when maxitems=1 and required=true

Jeroen Reijn
Administrator


Op 6 nov. 2012 20:22 schreef "Niels van Kampenhout" <[hidden email]> het volgende:
>
> Hello list,
>
> I have a small issue with the Content Blocks addon [1]. The use case
> is as follows:
>
> I have two compound types, let's call them A and B.
> In a document type, I have a "content blocks" field that allows the
> user to add either an A or a B. This works well.
> The content blocks field has required set to true, and maxitems=1.
> 'Required' works in that a newly created document can't be saved until
> either A or B has been added.
> 'Maxitems=1' works in that once either an A or a B has been added,
> it's not possible to add more.
> However, once an A or a B has been added, it can't be removed: the
> usual 'X' icon is not displayed. This means the user can't remove e.g.
> an A and replace it with a B.
> Setting required to false on the content blocks field brings back the
> 'X' but obviously now the user can save without any A or B added.
>
> This looks like a bug: I see no reason not to have the 'X' (remove
> item) option when the field is required. Instead, the validation of
> the document should fail on saving if there are 0 items in the content
> blocks field.
>
> WDYT?

Smells like a bug indeed. Could you file an issue in JIRA?

>
> Thanks,
> Niels
>
> [1] http://content-blocks.forge.onehippo.org/
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Content blocks bug? No remove item icon when maxitems=1 and required=true

Niels van Kampenhout-2
On Tue, Nov 6, 2012 at 11:00 PM, Jeroen Reijn <[hidden email]> wrote:

>
> Op 6 nov. 2012 20:22 schreef "Niels van Kampenhout"
> <[hidden email]> het volgende:
>
>
>>
>> Hello list,
>>
>> I have a small issue with the Content Blocks addon [1]. The use case
>> is as follows:
>>
>> I have two compound types, let's call them A and B.
>> In a document type, I have a "content blocks" field that allows the
>> user to add either an A or a B. This works well.
>> The content blocks field has required set to true, and maxitems=1.
>> 'Required' works in that a newly created document can't be saved until
>> either A or B has been added.
>> 'Maxitems=1' works in that once either an A or a B has been added,
>> it's not possible to add more.
>> However, once an A or a B has been added, it can't be removed: the
>> usual 'X' icon is not displayed. This means the user can't remove e.g.
>> an A and replace it with a B.
>> Setting required to false on the content blocks field brings back the
>> 'X' but obviously now the user can save without any A or B added.
>>
>> This looks like a bug: I see no reason not to have the 'X' (remove
>> item) option when the field is required. Instead, the validation of
>> the document should fail on saving if there are 0 items in the content
>> blocks field.
>>
>> WDYT?
>
> Smells like a bug indeed. Could you file an issue in JIRA?

Done: https://issues.onehippo.com/browse/HIPPLUG-533

Niels
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Content blocks bug? No remove item icon when maxitems=1 and required=true

Jeroen Hoffman


On 07-11-12 17:19, Niels van Kampenhout wrote:
> On Tue, Nov 6, 2012 at 11:00 PM, Jeroen Reijn<[hidden email]>  wrote:
>>
>> Op 6 nov. 2012 20:22 schreef "Niels van Kampenhout"
>> <[hidden email]>  het volgende:

...

>>>
>>> This looks like a bug: I see no reason not to have the 'X' (remove
>>> item) option when the field is required. Instead, the validation of
>>> the document should fail on saving if there are 0 items in the content
>>> blocks field.
>>>
>>> WDYT?
>>
>> Smells like a bug indeed. Could you file an issue in JIRA?
>
> Done: https://issues.onehippo.com/browse/HIPPLUG-533


I did some investigation and I am wondering if this could be moved to a CMS7
issue. The code determining this is in AbstractFieldPlugin#canRemoveItem:

if (field.getValidators().contains("required") && provider.size() == 1) {
   return false;
}

So for every multiple, node or property, you cannot remove the first item if
required=true. IMO These lines may actually be removed because it seems that for
required fields, first items are autocreated by the editor.

Allowing removing is okay if validation works.

WDYT
Jeroen
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Content blocks bug? No remove item icon when maxitems=1 and required=true

Frank van Lankvelt

On Fri, Nov 9, 2012 at 5:00 PM, Jeroen Hoffman <[hidden email]> wrote:


On 07-11-12 17:19, Niels van Kampenhout wrote:
On Tue, Nov 6, 2012 at 11:00 PM, Jeroen Reijn<[hidden email]>  wrote:

Op 6 nov. 2012 20:22 schreef "Niels van Kampenhout"
<[hidden email]>  het volgende:

...



This looks like a bug: I see no reason not to have the 'X' (remove
item) option when the field is required. Instead, the validation of
the document should fail on saving if there are 0 items in the content
blocks field.

WDYT?

Smells like a bug indeed. Could you file an issue in JIRA?

Done: https://issues.onehippo.com/browse/HIPPLUG-533


I did some investigation and I am wondering if this could be moved to a CMS7 issue. The code determining this is in AbstractFieldPlugin#canRemoveItem:

if (field.getValidators().contains("required") && provider.size() == 1) {
  return false;
}

So for every multiple, node or property, you cannot remove the first item if required=true. IMO These lines may actually be removed because it seems that for required fields, first items are autocreated by the editor.

this behavior can now not be overridden; perhaps we should move the check into a separate method?  ("shouldAddItemIfEmpty"?)
It's certainly complex enough ;-)  I wonder what type of block should be automatically added anyway; a default doesn't make a lot of sense to me.

Then it becomes straightforward for the contentblocksfieldplugin to override both methods and implement the desired behavior.  Agreed?

cheers, Frank
 
Allowing removing is okay if validation works.

WDYT
Jeroen

_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Content blocks bug? No remove item icon when maxitems=1 and required=true

Jeroen Hoffman


On 09-11-12 22:11, Frank van Lankvelt wrote:
>
> On Fri, Nov 9, 2012 at 5:00 PM, Jeroen Hoffman <[hidden email]

<snip/>

>     I did some investigation and I am wondering if this could be moved to a CMS7
>     issue. The code determining this is in AbstractFieldPlugin#__canRemoveItem:
>
>     if (field.getValidators().__contains("required") && provider.size() == 1) {
>        return false;
>     }
>
>     So for every multiple, node or property, you cannot remove the first item if
>     required=true. IMO These lines may actually be removed because it seems that
>     for required fields, first items are autocreated by the editor.
>
> this behavior can now not be overridden; perhaps we should move the check into a
> separate method?  ("shouldAddItemIfEmpty"?)
> It's certainly complex enough ;-)  I wonder what type of block should be
> automatically added anyway; a default doesn't make a lot of sense to me.
>
> Then it becomes straightforward for the contentblocksfieldplugin to override
> both methods and implement the desired behavior.  Agreed?

I tested out what happens if the above three lines are removed from
AbstractFieldPlugin. The remove item icon is shown again for all multiples with
one item but for regular compounds, clicking it will remove the current and will
immediately add a new one from prototype.

So it's not as simple as I hoped, now I will write an override of canRemoveItem
in ContentBlocksFieldPlugin.

And yes, agreed on the shouldAddItemIfEmpty, that will simplify overriding!

Jeroen






_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html