Skip to content

Commit

Permalink
Merge pull request #210 from edgarmueller/master
Browse files Browse the repository at this point in the history
Add multi-line support for string control
  • Loading branch information
edgarmueller committed Apr 4, 2016
2 parents be19b94 + 9df79f3 commit 507950b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
24 changes: 24 additions & 0 deletions components/renderers/controls/string/string-renderer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,28 @@ describe('String renderer', () => {
let input = angular.element(el[0].getElementsByClassName('jsf-control-string'));
expect(input.attr("readonly")).toBeDefined();
}));

it("should support text-areas if multi option is set", inject(($rootScope, $compile) => {
let scope = $rootScope.$new();
scope.schema = {
"properties": {
"name": {
"type": "string",
},
}
};
scope.uiSchema = {
"type": "Control",
"readOnly": true,
"scope": { "$ref": "#/properties/name" },
"options": {
"multi": true
}
};
scope.data = { "vegetarian": true };
let el = $compile('<jsonforms schema="schema" ui-schema="uiSchema" data="data"/>')(scope);
scope.$digest();
let input = angular.element(el[0].getElementsByClassName('jsf-control-string'));
expect(input.prop('tagName')).toBe("TEXTAREA");
}));
});
16 changes: 12 additions & 4 deletions components/renderers/controls/string/string-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ class StringRenderer implements JSONForms.IRenderer {
static inject = ['RenderDescriptionFactory'];

render(element: IControlObject, subSchema: SchemaElement, schemaPath: string, services: JSONForms.Services): JSONForms.IRenderDescription {
var control = JSONForms.RenderDescriptionFactory.createControlDescription(schemaPath, services, element);
control['template'] = `<jsonforms-control>
<input type="text" id="${schemaPath}" class="form-control jsf-control-string" ${element.readOnly ? 'readonly' : ''} data-jsonforms-model data-jsonforms-validation/>
</jsonforms-control>`;
let control = JSONForms.RenderDescriptionFactory.createControlDescription(schemaPath, services, element);

if (element['options'] != null && element['options']['multi']) {
control.template = `<jsonforms-control>
<textarea id="${schemaPath}" class="form-control jsf-control-string" ${element.readOnly ? 'readonly' : ''} data-jsonforms-model data-jsonforms-validation/>
</jsonforms-control>`
} else {
control.template = `<jsonforms-control>
<input type="text" id="${schemaPath}" class="form-control jsf-control-string" ${element.readOnly ? 'readonly' : ''} data-jsonforms-model data-jsonforms-validation/>
</jsonforms-control>`;
}

return control;
}

Expand Down

0 comments on commit 507950b

Please sign in to comment.