Skip to content

Commit 4221248

Browse files
committed
Add FieldAddon support to TextArea
Add FieldAddon support to TextArea
1 parent a2b83bd commit 4221248

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

src/main/java/io/asfjava/ui/core/form/TextArea.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
String placeHolder() default "";
1515

1616
String description() default "";
17+
18+
String fieldAddonLeft() default"";
19+
20+
String fieldAddonRight() default"";
1721

1822
boolean noTitle() default false;
1923

src/main/java/io/asfjava/ui/core/generators/TextAreaGenerator.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ public void generate(ObjectNode fieldFormDefinition, Field field) {
1414
fieldFormDefinition.put("key", field.getName());
1515
fieldFormDefinition.put("type", "textarea");
1616

17+
String fieldAddonLeft = annotation.fieldAddonLeft();
18+
if (!fieldAddonLeft.isEmpty()) {
19+
fieldFormDefinition.put("fieldAddonLeft", fieldAddonLeft);
20+
}
21+
22+
String fieldAddonRight = annotation.fieldAddonRight();
23+
if (!fieldAddonRight.isEmpty()) {
24+
fieldFormDefinition.put("fieldAddonRight", fieldAddonRight);
25+
}
26+
1727
String description = annotation.description();
1828
if (!description.isEmpty()) {
1929
fieldFormDefinition.put("description", description);

src/test/java/io/asfjava/ui/core/schema/UiFormSchemaGeneratorTest.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,46 @@ public void testGenerate_TextArea() throws JsonProcessingException {
246246
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].notitle", hasItem(true)));
247247
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].readonly", hasItem(true)));
248248

249+
}
250+
251+
public void testGenerate_TextArea_WithFieldAddOnLeft() throws JsonProcessingException {
252+
UiForm ui = UiFormSchemaGenerator.get().generate(TextAreaForm2.class);
253+
254+
String json = new ObjectMapper().writeValueAsString(ui);
255+
Assert.assertThat(json, hasJsonPath("$.schema.properties.address.title", equalTo("Address")));
256+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')]", hasSize(1)));
257+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].description", hasItem("This is textarea")));
258+
Assert.assertThat(json,
259+
hasJsonPath("$.form[?(@.key=='address')].placeholder", hasItem("Fill your address please")));
260+
Assert.assertThat(json,
261+
hasJsonPath("$.form[?(@.key=='address')].validationMessage", hasItem("this is a validation msg")));
262+
// Assert.assertThat(json,
263+
// hasJsonPath("$.form[?(@.key=='password')].type",hasItem("textArea")));
264+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].notitle", hasItem(true)));
265+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].readonly", hasItem(true)));
266+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].fieldAddonLeft", hasItem("@")));
267+
268+
269+
}
270+
271+
public void testGenerate_TextArea_WithFieldAddOnRight() throws JsonProcessingException {
272+
UiForm ui = UiFormSchemaGenerator.get().generate(TextAreaForm3.class);
273+
274+
String json = new ObjectMapper().writeValueAsString(ui);
275+
Assert.assertThat(json, hasJsonPath("$.schema.properties.address.title", equalTo("Address")));
276+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')]", hasSize(1)));
277+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].description", hasItem("This is textarea")));
278+
Assert.assertThat(json,
279+
hasJsonPath("$.form[?(@.key=='address')].placeholder", hasItem("Fill your address please")));
280+
Assert.assertThat(json,
281+
hasJsonPath("$.form[?(@.key=='address')].validationMessage", hasItem("this is a validation msg")));
282+
// Assert.assertThat(json,
283+
// hasJsonPath("$.form[?(@.key=='password')].type",hasItem("textArea")));
284+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].notitle", hasItem(true)));
285+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].readonly", hasItem(true)));
286+
Assert.assertThat(json, hasJsonPath("$.form[?(@.key=='address')].fieldAddonRight", hasItem("@")));
287+
288+
249289
}
250290

251291
@Test
@@ -446,6 +486,26 @@ public String getPassword() {
446486
}
447487
}
448488

489+
class TextAreaForm2 implements Serializable {
490+
491+
@TextArea(title = "Address", placeHolder = "Fill your address please", fieldAddonLeft = "@", description = "This is textarea", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
492+
private String address;
493+
494+
public String getAddress() {
495+
return address;
496+
}
497+
}
498+
499+
class TextAreaForm3 implements Serializable {
500+
501+
@TextArea(title = "Address", placeHolder = "Fill your address please",fieldAddonRight = "@", description = "This is textarea", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)
502+
private String address;
503+
504+
public String getAddress() {
505+
return address;
506+
}
507+
}
508+
449509
class TextAreaForm implements Serializable {
450510

451511
@TextArea(title = "Address", placeHolder = "Fill your address please", description = "This is textarea", noTitle = true, validationMessage = "this is a validation msg", readOnly = true)

0 commit comments

Comments
 (0)