Skip to content

Commit

Permalink
IQSS#6000. Add dropdown mode for autocompletion for vocabularies smal…
Browse files Browse the repository at this point in the history
…ler than 20 entries.
  • Loading branch information
poikilotherm committed Jul 31, 2019
1 parent e3db784 commit 2a5a936
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/DatasetField.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ public Collection<ControlledVocabularyValue> completeVocabulary(String query) {
}
return filtered;
}

/**
* Check if the number of vocables in a vocabulary is less or equal to the given maximum.
* @param max Maximum size of vocabulary before returning false
* @return true when vocabulary contains less or equal entries, false otherwise.
*/
public boolean isSmallVocabulary(int max) {
return this.getDatasetFieldType().getControlledVocabularyValues().size() < max+1;
}

// HELPER METHODS
public DatasetFieldValue getSingleValue() {
Expand Down
8 changes: 4 additions & 4 deletions src/main/webapp/metadataFragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@
<ui:fragment rendered="#{dsf.datasetFieldType.controlledVocabulary}">
<p:autoComplete rendered="#{!dsf.datasetFieldType.allowMultiples}"
value="#{singleControlledVocabularyValue}" converter="controlledVocabularyValueConverter"
multiple="false" forceSelection="true" dynamic="true"
multiple="false" forceSelection="true" dynamic="true" dropdown="#{dsf.isSmallVocabulary(20)}"
var="cvv" itemLabel="#{cvv.localeStrValue}" itemValue="#{cvv}"
completeMethod="#{dsf.completeVocabulary}">
</p:autoComplete>
<p:autoComplete rendered="#{dsf.datasetFieldType.allowMultiples}"
value="#{dsf.controlledVocabularyValues}" converter="controlledVocabularyValueConverter"
multiple="true" forceSelection="true" dynamic="true"
multiple="true" forceSelection="true" dynamic="true" dropdown="#{dsf.isSmallVocabulary(20)}"
var="cvv" itemLabel="#{cvv.localeStrValue}" itemValue="#{cvv}"
completeMethod="#{dsf.completeVocabulary}">
</p:autoComplete>
Expand Down Expand Up @@ -205,13 +205,13 @@
<div jsf:rendered="#{subdsf.datasetFieldType.controlledVocabulary}">
<p:autoComplete rendered="#{!subdsf.datasetFieldType.allowMultiples}"
value="#{singleControlledVocabularyValue}" converter="controlledVocabularyValueConverter"
multiple="false" forceSelection="true" dynamic="true"
multiple="false" forceSelection="true" dynamic="true" dropdown="#{subdsf.isSmallVocabulary(20)}"
var="cvv" itemLabel="#{cvv.localeStrValue}" itemValue="#{cvv}"
completeMethod="#{subdsf.completeVocabulary}">
</p:autoComplete>
<p:autoComplete rendered="#{subdsf.datasetFieldType.allowMultiples}"
value="#{subdsf.controlledVocabularyValues}" converter="controlledVocabularyValueConverter"
multiple="true" forceSelection="true" dynamic="true"
multiple="true" forceSelection="true" dynamic="true" dropdown="#{subdsf.isSmallVocabulary(20)}"
var="cvv" itemLabel="#{cvv.localeStrValue}" itemValue="#{cvv}"
completeMethod="#{subdsf.completeVocabulary}">
</p:autoComplete>
Expand Down

0 comments on commit 2a5a936

Please sign in to comment.