Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
FormAPI - onReplicantBeforeAdd
jon1
Hi
First things first - I'm working with FormAPI on TeamSite 6.5.
I have an "or" replicant container like so (I've removed the items within the image and paragraph containers for brevity). The (very!) basic premise is that users can add paragraphs and images in any order within the "Content choice" container, up to a limit of X paragraphs and Y images: -
<container name="Content choice" min="1" max="100" combination="or">
<container name="Paragraph">
<!-- paragraph items ... -->
</container>
<container name="Image">
<!-- image items .... -->
</container>
</container>
So - I'm trying to enforce a replicant max limit on paragraphs and images, in any order.
If I put max and min attributes on the "Paragraph" and "Image" containers, they force the user to enter paragraphs and images sequentially, e.g. para, para, para, image, image image, rather than the para, image, para, image mix I'm looking for.
I have looked at using the onReplicantBeforeAdd event to trap additions to the "Content choice" container, BUT the problem is that I can see no way to determine what type of container (e.g. Paragraph or Image) is being added. The event receives a reference to the "Content choice" container, and the index of the replicant position, but how can I tell exactly what is being added to the DCT?
I tried an (almost successful) alternate approach of trapping the "OnReplicantAdded" event, and tried to immediately remove the newly added container if the limit had already been reached, but the event seems to be fired before the new container has been properly registered.
For example when the OnReplicantAdded event fires, I can identify the index and name of the newly added image/para container within the "Content choice" container, but when I try to delete the added container I get an invalid argument JS error.
Have RTFM many times now and seen a couple of similar threads on this forum, but I'm close to pulling out my hair over this one.
Any pointers?
Thanks in advance
jon
Find more posts tagged with
Comments
jbonifaci
I haven't played with OnReplicantBeforeAdd and don't have access to 6.5 to do so, but if you can't get that working, what about doing your validation using OnReplicantAdded instead? You can then determine which replicant they added and remove it if they are over the max. Just something to consider if you can't get something working with OnReplicantBeforeAdd.
~Jeff
jon1
Jeff
Thanks for the reply.
I have tried exactly what you suggest with OnReplicantAdded - the problem is that when I attempt to execute a "deleteInstance" within this event on the newly added replicant, I get a JS error. I thought it might just be that I had the syntax of the "deleteInstance" call wrong, so I tested by deleting an existing replicant (e.g. the one *before* the new paragraph or image), and this worked fine.
This would suggest that the new replicant hadn't been fully registered when I tried to delete it, or something similar. I can set the visibility of the new replicant, move it to another index, etc, but I can't delete it!
I have to disappear for a couple of days, but when I get back I'll post some code and demonstrate what I mean.
Cheers
jon