1

A large form has several input fields so that they are grouped inside primefaces tabview tabs. Some of these fields are mandatory. When the user tries to submit, it gets the required message, but the user has to scroll through all the tabes to locate the fields missing fields. Is there any way to highlight tabs with missing values?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Buddhika Ariyaratne
  • 2,339
  • 6
  • 51
  • 88

2 Answers2

2

I would personally do this client-side.

  1. I'd start with checking IF a validation failed in general or not like in the PrimeFaces solution in here:
  2. In the javascript function that you can call, I'd find the surrounding form via jquery.
  3. And from that form down I'd find via jquery all inputs with a css class that indicate an error.
  4. From each error I'd find the ancestor element that is the tab of the div (this might be where you need to be most creative, but it IS all plain jquery with wich many can help you if you make it a plain jquery question) and add a css class to this so you can style it 'in error'.
  5. I'd find, again with jquery, the first tab that has errors and 'fake' a click on it.
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • An example can be found on this page: [Primefaces: Displaying Tabs with Validation Errors](http://stickysession.com/2016/03/primefaces-displaying-tabs-with-validation-errors/) – ltlBeBoy Jun 15 '20 at 11:54
1

You can do server-side validation. So if a validation error occurred you know the tab that the error is locate. Then you can use the activetabindex of TabView and activate the tab that you want.

Then you can use Spotlite as @fuggerjak61 said to locate the missing/not valid fields.

tsotzolas
  • 387
  • 1
  • 10
  • 1
    I assume the validation is already server side (common practice with JSF). So that makes your second statement _" So if a validation error occurred you know the tab that the error is locate. "_ the main 'problem'... How do you know the tab? How do you retrieve that? And what if you have multiple tags? Than you get the first one, but how do you get to the second? – Kukeltje Sep 29 '19 at 13:58
  • 1
    I suppose that you know what fields have each tab. – tsotzolas Sep 29 '19 at 14:01
  • I used the required attribute to validate. So difficult to validate at server side. – Buddhika Ariyaratne Sep 29 '19 at 16:36