minor fix in tags panel

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@132484 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-10-03 15:30:27 +00:00
parent f671ef0280
commit d8c6205b44
1 changed files with 23 additions and 16 deletions

View File

@ -37,6 +37,9 @@ public class TagsPanel extends Composite{
@UiField FocusPanel focusPanelTags;
@UiField Popover popoverTags;
// regular expression for tags
private static final String REGEX_TAG = "^[a-zA-Z0-9]*$";
// tags list
private List<String> tagsList = new ArrayList<String>();
@ -60,6 +63,18 @@ public class TagsPanel extends Composite{
);
}
@UiHandler("tagsEnterTextBox")
void onAddTag(KeyDownEvent event){
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
if (!tagsEnterTextBox.getValue().trim().isEmpty()) {
addTagElement(tagsEnterTextBox);
}
}
}
/**
* Add the tag as an element (inserted by the user)
*/
@ -75,14 +90,14 @@ public class TagsPanel extends Composite{
// ckan accepts only alphanumeric values
String[] subTags = itemBox.getValue().split(" ");
if(subTags.length == 1){
if(!subTags[0].matches("^[a-zA-Z0-9]*$"))
if(!subTags[0].matches(REGEX_TAG))
return;
if(subTags[0].length() <= 1)
return;
}else{
for (int i = 0; i < subTags.length; i++) {
String subTag = subTags[i];
if(!subTag.matches("^[a-zA-Z0-9]*$"))
if(!subTag.matches(REGEX_TAG))
return;
}
}
@ -121,14 +136,14 @@ public class TagsPanel extends Composite{
// ckan accepts only alphanumeric values
String[] subTags = tag.split(" ");
if(subTags.length == 1){
if(!subTags[0].matches("^[a-zA-Z0-9]*$"))
if(!subTags[0].matches(REGEX_TAG))
return;
if(subTags[0].length() <= 1)
return;
}else{
for (int i = 0; i < subTags.length; i++) {
String subTag = subTags[i];
if(!subTag.matches("^[a-zA-Z0-9]*$"))
if(!subTag.matches(REGEX_TAG))
return;
}
}
@ -173,18 +188,10 @@ public class TagsPanel extends Composite{
}
@UiHandler("tagsEnterTextBox")
void onAddTag(KeyDownEvent event){
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
if (!tagsEnterTextBox.getValue().trim().isEmpty()) {
addTagElement(tagsEnterTextBox);
}
}
}
/**
* Return the tag list
* @return
*/
public List<String> getTags() {
return tagsList;
}