Commit e5057b0b by Owen Ryan Ang

modify schema for readOnly, implemented on string fields.

parent eca04648
...@@ -271,7 +271,7 @@ const inputHidden = (key, validation) => { ...@@ -271,7 +271,7 @@ const inputHidden = (key, validation) => {
* @returns * @returns
* created input field element * created input field element
*/ */
const inputString = (key, validation) => { const inputString = (key, validation, readOnly) => {
try { try {
const { const {
mandatory, mandatory,
...@@ -286,6 +286,12 @@ const inputString = (key, validation) => { ...@@ -286,6 +286,12 @@ const inputString = (key, validation) => {
input.setAttribute('autocomplete', 'off') input.setAttribute('autocomplete', 'off')
input.addEventListener('focusout', handleInput) input.addEventListener('focusout', handleInput)
// add readonly attribute if set to true
if (readOnly) {
input.setAttribute('readonly', 'true');
}
if (fieldLength >= 31 && fieldLength <= 60) { if (fieldLength >= 31 && fieldLength <= 60) {
input = document.createElement('TEXTAREA') input = document.createElement('TEXTAREA')
input.setAttribute('rows', 2) input.setAttribute('rows', 2)
...@@ -1570,7 +1576,7 @@ const inputGeoTag = (key, validation) => { ...@@ -1570,7 +1576,7 @@ const inputGeoTag = (key, validation) => {
* @returns * @returns
* created input field element * created input field element
*/ */
const inputDropdown = (key, validation) => { const inputDropdown = (key, validation, readOnly) => {
try { try {
const { mandatory, options } = validation; const { mandatory, options } = validation;
const input = document.createElement('select'); const input = document.createElement('select');
...@@ -1579,6 +1585,11 @@ const inputDropdown = (key, validation) => { ...@@ -1579,6 +1585,11 @@ const inputDropdown = (key, validation) => {
input.setAttribute('name', `${key}`); input.setAttribute('name', `${key}`);
input.classList.add('dropdown-input'); input.classList.add('dropdown-input');
if (readOnly) {
input.setAttribute('readonly', 'true');
}
$(input).select2(); $(input).select2();
$(input).on('select2:select', function (e) { $(input).on('select2:select', function (e) {
...@@ -1743,12 +1754,13 @@ const deconstruct = async (section, container, classAttribute) => { ...@@ -1743,12 +1754,13 @@ const deconstruct = async (section, container, classAttribute) => {
for (const key in section) { for (const key in section) {
const { const {
fieldLabel, hidden fieldLabel, hidden, readOnly
} = section[key] } = section[key]
const validation = getValidation(key, schema) const validation = getValidation(key, schema)
const { mandatory } = validation; const { mandatory } = validation;
if (hidden) { if (hidden) {
const hiddenField = document.createElement('div') // will contain input field and label const hiddenField = document.createElement('div') // will contain input field and label
...@@ -1826,14 +1838,14 @@ const deconstruct = async (section, container, classAttribute) => { ...@@ -1826,14 +1838,14 @@ const deconstruct = async (section, container, classAttribute) => {
case 'textarea': case 'textarea':
case 'alphanumeric': case 'alphanumeric':
case 'email': case 'email':
input = inputString(key, validation) input = inputString(key, validation, readOnly)
break break
case 'alphabet': case 'alphabet':
input = inputString(key, validation) input = inputString(key, validation, readOnly)
break break
case 'specific': case 'specific':
case 'dropdown': case 'dropdown':
input = inputDropdown(key, validation) input = inputDropdown(key, validation, readOnly)
break break
case 'numeric': case 'numeric':
input = inputNumeric(key, validation) input = inputNumeric(key, validation)
......
...@@ -1510,7 +1510,8 @@ ...@@ -1510,7 +1510,8 @@
"fieldLength" : 20.0, "fieldLength" : 20.0,
"collection" : "alphanumeric", "collection" : "alphanumeric",
"mandatory" : true "mandatory" : true
} },
"readOnly" : true
}, },
"registered_owner" : { "registered_owner" : {
"fieldLabel" : "Registered Owner", "fieldLabel" : "Registered Owner",
...@@ -1519,7 +1520,8 @@ ...@@ -1519,7 +1520,8 @@
"fieldLength" : 20.0, "fieldLength" : 20.0,
"collection" : "alphanumeric", "collection" : "alphanumeric",
"mandatory" : true "mandatory" : true
} },
"readOnly" : true
}, },
"business_address" : { "business_address" : {
"fieldLabel" : "Business Address", "fieldLabel" : "Business Address",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment