Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support self-closing setvalue without value #615

Merged
merged 1 commit into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/main/java/org/javarosa/xform/parse/XFormParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -786,11 +786,12 @@ public void parseSetValueAction(ActionController source, Element e) {

registerActionTarget(treeref);
if (valueExpression == null) {
if (e.getChildCount() == 0 || !e.isText(0)) {
throw new XFormParseException("No 'value' attribute and no inner value set in <setvalue> associated with: " + treeref, e);
String value = "";
if (e.getChildCount() > 0 && e.isText(0)) {
value = e.getText(0);
}
//Set expression
action = new SetValueAction(treeref, e.getText(0));

action = new SetValueAction(treeref, value);
} else {
try {
action = new SetValueAction(treeref, valueExpression.equals("") ? new XPathStringLiteral("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void setvalue_withInnerEmptyString_clearsTarget() throws IOException {
t("a-field", "12")
)),
bind("/data/a-field").type("int"),
setvalueLiteral("odk-instance-first-load", "/data/a-field", "")
setvalue("odk-instance-first-load", "/data/a-field")
)
),
body(
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/org/javarosa/core/util/XFormsElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ static XFormsElement setvalue(String event, String ref, String value) {
return t("setvalue event=\"" + event + "\" ref=\"" + ref + "\" value=\"" + value + "\"");
}

static XFormsElement setvalue(String event, String ref) {
return t("setvalue event=\"" + event + "\" ref=\"" + ref + "\"");
}

static XFormsElement setvalueLiteral(String event, String ref, String innerHtml) {
return t("setvalue event=\"" + event + "\" ref=\"" + ref + "\"", innerHtml);
}
Expand Down