Foren

Validation on number of autoFields.

thumbnail
Himanshu Bhandari, geändert vor 7 Jahren.

Validation on number of autoFields.

Regular Member Beiträge: 148 Beitrittsdatum: 09.05.14 Neueste Beiträge
Hi, I am into a situation where I need to add multiple text boxes on click which I get from Liferay.AutoFields JS API. I applied it and it is working. Now I am having problem to validate the number of input boxes that can be added to the form. Is there any solution to that, please let me know if API is providing this functionality already.

I checked in Liferay control panel where multiple phone numbers of the users can be added using the same API. To test that out I have added more than 50 phone numbers( empty ) and the portal allowed me to save them all... surprised.
Thanks.
thumbnail
Andrew Jardine, geändert vor 7 Jahren.

RE: Validation on number of autoFields. (Antwort)

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
Hi Himanshu,

Does't look like it. I had a look at the auto_fields.js file (in Liferay 6.2 -- I just realized that you didn't specify a version) and I can see this--

addRow: function(node) {
						var instance = this;

						var clone = instance._createClone(node);

						clone.resetId();

						node.placeAfter(clone);

						Liferay.Util.focusFormField(clone.one('input[type=text], input[type=password], textarea'));

						instance.fire(
							'clone',
							{
								guid: instance._guid,
								originalRow: node,
								row: clone
							}
						);

						if (instance._sortable) {
							instance._addHandleClass(clone);
						}
					},


I don't see anything in there that checks for constraints. I think you have a couple of options for what you want to do. You could try attaching your own listener and disabling the button to add more when your "max number is reached" -- or alternatively, and probably a cleaner solution, create your own AUI module that references this one and in the addRow function of your module do the count check (you could keep your own counter in your module which would also save you counting DOM nodes).

But in short -- I don't think such a configuration option exists.
thumbnail
Himanshu Bhandari, geändert vor 7 Jahren.

RE: Validation on number of autoFields.

Regular Member Beiträge: 148 Beitrittsdatum: 09.05.14 Neueste Beiträge
Hi Andrew Jardine,
Thanks for replying. I also looked at auto_fields.js and couldn't find such validation. Then I started looking at Liferay's portlets and also there was nothing. For the suggestions that you have given I am unable to perform as I have very little knowledge about them.

Thanks.
thumbnail
Andrew Jardine, geändert vor 7 Jahren.

RE: Validation on number of autoFields.

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
Creating a custom AUI module is only as complicated as you want to make the module. I'm still learning to be honest but, like portlets, there is an art to building them that you can only really refine as you go. They may look complicated at first but I found it easier to pick up that portlets (way back when I started with Liferay)

If you want to give it a shot, this thread helped me get started when I first ventured into these waters -
https://web.liferay.com/community/forums/-/message_boards/message/39311962
thumbnail
Himanshu Bhandari, geändert vor 7 Jahren.

RE: Validation on number of autoFields.

Regular Member Beiträge: 148 Beitrittsdatum: 09.05.14 Neueste Beiträge
Surely I would give it a try, Thanks emoticon