Commit e5057b0b by Owen Ryan Ang

modify schema for readOnly, implemented on string fields.

parent eca04648
......@@ -271,7 +271,7 @@ const inputHidden = (key, validation) => {
* @returns
* created input field element
*/
const inputString = (key, validation) => {
const inputString = (key, validation, readOnly) => {
try {
const {
mandatory,
......@@ -286,6 +286,12 @@ const inputString = (key, validation) => {
input.setAttribute('autocomplete', 'off')
input.addEventListener('focusout', handleInput)
// add readonly attribute if set to true
if (readOnly) {
input.setAttribute('readonly', 'true');
}
if (fieldLength >= 31 && fieldLength <= 60) {
input = document.createElement('TEXTAREA')
input.setAttribute('rows', 2)
......@@ -1570,7 +1576,7 @@ const inputGeoTag = (key, validation) => {
* @returns
* created input field element
*/
const inputDropdown = (key, validation) => {
const inputDropdown = (key, validation, readOnly) => {
try {
const { mandatory, options } = validation;
const input = document.createElement('select');
......@@ -1579,6 +1585,11 @@ const inputDropdown = (key, validation) => {
input.setAttribute('name', `${key}`);
input.classList.add('dropdown-input');
if (readOnly) {
input.setAttribute('readonly', 'true');
}
$(input).select2();
$(input).on('select2:select', function (e) {
......@@ -1743,12 +1754,13 @@ const deconstruct = async (section, container, classAttribute) => {
for (const key in section) {
const {
fieldLabel, hidden
fieldLabel, hidden, readOnly
} = section[key]
const validation = getValidation(key, schema)
const { mandatory } = validation;
if (hidden) {
const hiddenField = document.createElement('div') // will contain input field and label
......@@ -1826,14 +1838,14 @@ const deconstruct = async (section, container, classAttribute) => {
case 'textarea':
case 'alphanumeric':
case 'email':
input = inputString(key, validation)
input = inputString(key, validation, readOnly)
break
case 'alphabet':
input = inputString(key, validation)
input = inputString(key, validation, readOnly)
break
case 'specific':
case 'dropdown':
input = inputDropdown(key, validation)
input = inputDropdown(key, validation, readOnly)
break
case 'numeric':
input = inputNumeric(key, validation)
......
......@@ -1510,7 +1510,8 @@
"fieldLength" : 20.0,
"collection" : "alphanumeric",
"mandatory" : true
}
},
"readOnly" : true
},
"registered_owner" : {
"fieldLabel" : "Registered Owner",
......@@ -1519,7 +1520,8 @@
"fieldLength" : 20.0,
"collection" : "alphanumeric",
"mandatory" : true
}
},
"readOnly" : true
},
"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