[OJS] Make fields mandatory, display the * sign and understand why translation value is not being used in mandatory field warning

Hello all, @asmecher, @rcgillis , @NateWr ,
Description of issue or problem I’m having:
I’m in need of making userUrl and biography fields mandatory. I understood how to use the formValidatorLocale while I was writing this message. So, apparently making the fields mandatory is working correctly. Please check if everything is fine or if I missed something.

During my testing I came up with other problems to solve:

  1. I’m unable to display the * sign on the required fields

  2. There’s a translation text being displayed that is nowhere to be found in locale files.
    The content is apparently from key validator.filled or validator.required, as the values are the same in English. But, the text that is displayed in the contributor form in Portuguese doesn’t exist in our translation files. The content in locale files is “Campo obrigatório”, but “Este campo é requerido.” is being shown. What’s going on?

Steps I took leading up to the issue:
I searched the forum and found a few ideas here to make fields mandatory, but the * sign on the label is not showing, although validation seems to be working. I couldn’t find the code to add the with the required=“true”… It seems to be from a different version.

What I tried to resolve the issue:
In: controllers/grid/users/author/form/PKPAuthorForm.inc.php

$this->addCheck(new FormValidatorUrl($this, 'userUrl', 'required', 'user.profile.form.urlInvalid'));


$this->addCheck(new FormValidatorLocale($this, 'biography', 'required', 'user.profile.form.biographyRequired', $this->defaultLocale));

In: templates/common/userDetails.tpl
I set

{if $userUrlRequired}
                                {assign var="userUrlRequired" value=true}
                                {assign var="userUrlRequired" value=false}

                        {fbvElement type="text" label="user.url" name="userUrl" id="userUrl" value=$userUrl maxlength="255" inline=true size=$fbvStyles.size.SMALL required=$userUrlRequired}


{if $biographyRequired}
                                {assign var="biographyRequired" value=true}
                                {assign var="biographyRequired" value=false}

                        {fbvElement type="textarea" label="user.biography" multilingual="true" name="biography" id="biography" rich=true value=$biography required=$biographyRequired}

Application Version - e.g., OJS 3.1.2:
I’m trying this on OJS
Is there anything else I need to do or this would be enough?

Additional information, such as screenshots and error log messages if applicable:
Figure 1 - Initial error messages seem ok, except that “Este campo é requerido.” doesn’t exist in locale files

Hi @ramon,

  1. Are you assigning values for variables $userUrlRequired and $biographyRequired somewhere?
  2. Looks like it’s from the JQuery validation plugin.

Hello @Vitaliy ,

The variables I copied the way other variables are defined on the same file, assuming that they are set in the classes file.

I eventually found the message.
I used grep -Ri “text” but the jquery messages are HTML encoded, and it would never find the “é”… If I’d known, I would search for “é”.

No, I don’t think that they are defined there.
Defined variables are listed in the doc block of the userDetails.tpl: pkp-lib/userDetails.tpl at 0f727b565929b04ddcbc0620cfa05f7471635364 · pkp/pkp-lib · GitHub

See also: pkp-lib/authorForm.tpl at 0f727b565929b04ddcbc0620cfa05f7471635364 · pkp/pkp-lib · GitHub
pkp-lib/userDetailsForm.tpl at 0f727b565929b04ddcbc0620cfa05f7471635364 · pkp/pkp-lib · GitHub

You may want to define them or just use required="true"