OMP: How to change text field to select (dropdown) on submission form?

Hi,
I have a request to change one text field on submission form to select field (dropdown), but when I change

{fbvFormSection label="common.subjects"}
			{fbvElement type="keyword" id="subjects" subLabelTranslate=true multilingual=true current=$subjects disabled=$readOnly}

to HTML

<select id="subjects">
  <option value="option1">Option 1</option>
  <option value="option2">Option 2</option>
</select>

then this field is not saved.

I have seen this should be possible with FBV, but I have no clue how to make select field with it.

Hi @adnank,

To make this happen, you’ll have to change more than what you’re trying to do here. It’s not a trivial change, and you should have some PHP skills.

If you willing to do this, I recommend you to take a look at the form object that handles this template. Check the file lib/pkp/classes/submission/PKPSubmissionMetadataFormImplementation.inc.php. You will have to change the initData(), readInputData() and execute() methods so the form can:

1 - initiate your select list with keywords;
2 - read the user selected keywords;
3 - execute the form and save them as controlled vocabularies associated with the submission;

You’ll have to create a list with possible selectable keywords also. That can be done manually inside the database, with a query, or you can create an interface to allow editors controlling what’s in the list. In both cases you might want to use the controlled vocabularies structure.

Let me know if you have more questions on this and I’ll try to help.

Cheers,
Bruno

Hi @beghelli, thank you for advice. I have successfully added new fields to submission form, which are saved in submission_settings, I just thought subjects field is handled by OMP, as it is already there and I just want to change its HTML type (representation) - text field to select field, but it seems like it’s no case.

Another try:
In PKPSubmissionMetadataFormImplementation.inc.php in initData I added to $formData array:

'newSubjects' => $submission->getNewSubjects(null) // Localized

and also to readInputData() and getLocaleFieldNames() at the end of return I added ‘newSubjects’. In execute function:

$submission->setNewSubjects($this->_parentForm->getData('newSubjects'), null); // Localized

Then in Submission.inc.php created two new functions:

function getNewSubjects($locale) {
		return $this->getData('newSubjects', $locale);
	}

function setNewSubjects($newSubjects, $locale) {
		return $this->setData('newSubjects', $newSubjects, $locale);
	}

I added to submissionMetadataFormFields.tpl

<select id="newSubjects" name="newSubjects" label="common.newSubjects">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

but again, value of newSubjects is not saved in db. Any advice :sweat: ? Thanks

Hi @adnank,

Keywords and subjects are actually handled by the controlled vocabularies structure. You can see that happening at line 93 of the PKPSubmissionMetadataFormImplementation.inc.php file.

I recommend you to keep using that, because other parts of the system will be able to track down your subjects and keywords (search for example) if you do so.

But, if you’re willing to save the new subjects (as you call) into the submission settings page, you will have to add the setting name into the getLocaleFieldNames() method, in classes/monograph/MonographDAO.inc.php file.

Cheers,
Bruno

I replicated what I did with other field I save in submission_settings, and also listened to you (added setting name in getLocaleFieldNames method in MonographDAO), but it is not saved again. The only difference is in template file. For first data I used

{fbvFormSection title="common.shortSummaryEn" for="shortSummaryEn"}
		{fbvElement type="textarea" multilingual=true name="shortSummaryEn" id="shortSummaryEn" value=$shortSummaryEn rich=true readonly=$readOnly}
{/fbvFormSection}

and everything is fine with it - it is saved in submission settings, and for newSubjects I used code in previous post. I am guessing that plain HTML elements are not handled properly and maybe I should use fbvElement of type “select”. Could this be the case? Do you know syntax for that, as I failed to find it though I am searhing for it for 3 days :S

Hi @adnank,

The HTML should work. I think that your list is not a localized setting. I got confused and that’s why I said to you to add the setting name into the getLocaleFieldNames(), but for a setting that’s not localized, you should use getAdditionalFieldNames() instead.

Try that and let me know.

Thanks,
Bruno

What I have found with the form fields in the Meta Data form:

  • The text fields end with a “[en_US]” in their names as though that is needed.
  • The select fields lack this in their names.
  • When I edit the form name (via inspect element to open up the HTML DOM), to add in the [en_US] to the form name, the form value is stored.
  • When the form is reloaded, the value is properly set from the database.

So: do should I add in the locale value in the templating or is this a bug?

Hi @dewolfe001,
I have the same problem on my ojs-3.1.1-4 stable

On my /lib/pkp/classes/submission/PKPSubmissionMetadataFormImplementation.inc.php

  • initdata($submission) added
    'newField' => $submission->getNewField('newField') //testing
  • readinputData() added
    newField
  • getLocaleFieldNames() added
    newField
  • getTagitFieldNames() added
    newField
  • execute() added
    $submission->setNewField($this->_parentForm->getData('newField'));

I created get and set functions on /lib/pkp/classes/submission/Submission.inc.php

function getnewField(){
		return $this->getData('newField');
	}
	
	function setNewField($newField){
		return $this->setData('newField', $newField);
	}

I modified: /templates/submission/submissionMetadataFormFields.tpl

{capture assign="languagesField"}
	{capture assign="sectionDescription"}{if !$readOnly}submission.submit.metadataForm.tip{/if}{/capture}
	{fbvFormSection description=$sectionDescription title="common.languages"}
{php}
	$this->assign("myOptions", array( 
	        op1 => "Option1", 
		    op2 => "Option2", 
		    op3 => "Option3", 
	));
    $this->assign("newField", $newField);		
		{/php}		

		{fbvElement label="submission.submit.submissionLocaleDescription" required="true" type="select" id="newField" from=$myOptions selected=$newField translate=false  size=$fbvStyles.size.MEDIUM}

	{/fbvFormSection}

{/capture}
{include file="core:submission/submissionMetadataFormFields.tpl"}

I would like to save on my DB op1

I created a new post a few days:

Regards,
xavi.