- Home
- Forum
- JavaScript - EJ 2
- Hide/Show custom fields on Form
Hide/Show custom fields on Form
Hi, i have the following scheduler and couple of custom fields on the form. These custom fields have a dropdown as datasource. Is there a possibility to hide some of these fields based on the selection of other field? In the scheduler below, i have eventtype and drilltype fields. based on the choice in the eventtype, i would like to hide the drilltype field. Can you please let me know if it is possible?
Hi Naveen Davuluri,
Based on the shared details, we
have achieved your requirement. Depending on the choice in the eventType, the drillType field will be hidden. we
have attached the code snippet and a sample demonstration of the solution.
Please try it and let us know if you need any further assistance.
Sample: https://stackblitz.com/edit/jluasf74-tl7afn1v?file=index.js
|
popupOpen: function (args) { if (args.type === 'Editor') { const drillTypeElement = args.element.querySelector('.drill-type') if (drillTypeElement) { if ( args.data.EventType && args.data.EventType === 'public-event') { drillTypeElement.style.display = "none" } else { drillTypeElement.style.display = "" } } // Create required custom elements in initial time if (!args.element.querySelector('.custom-field-row')) { var row = new ej.base.createElement('div', { className: 'custom-field-row' }); var formElement = args.element.querySelector('.e-schedule-form'); formElement.firstChild.insertBefore(row, args.element.querySelector('.e-title-location-row')); var container = new ej.base.createElement('div', { className: 'custom-field-container' }); var inputEle = new ej.base.createElement('input', { className: 'e-field', attrs: { name: 'EventType' } }); container.appendChild(inputEle); row.appendChild(container); var drowDownList = new ej.dropdowns.DropDownList({ dataSource: [ { text: 'Public Event', value: 'public-event' }, { text: 'Maintenance', value: 'maintenance' }, { text: 'Commercial Event', value: 'commercial-event' }, { text: 'Family Event', value: 'family-event' } ], fields: { text: 'text', value: 'value' }, value: args.EventType, change: function(args) { if (drillTypeObj) { drillTypeObj.parentElement.style.display = ''; var eventTypeValue = args && args.itemData && args.itemData.value ? args.itemData.value : ''; // Hide DrillType field if EventType is 'Public Event' if (eventTypeValue === 'public-event') { drillTypeObj.parentElement.style.display = 'none'; // Hide DrillType } }
}, floatLabelType: 'Always', placeholder: 'Event Type' }); drowDownList.appendTo(inputEle); inputEle.setAttribute('name', 'EventType'); var drillTypeObj = new ej.base.createElement('input', { className: 'e-field', attrs: { name: 'DrillType' } }); container.appendChild(drillTypeObj ); var drowDownList = new ej.dropdowns.DropDownList({ cssClass: 'drill-type', dataSource: [ { text: 'Type 1', value: 'Type- 1' }, { text: 'Type 2', value: 'Type - 2 ' }, { text: 'Type 3', value: 'Type - 3' }, ], fields: { text: 'text', value: 'value' }, floatLabelType: 'Always', placeholder: 'DrillType', value: args.DrillType, }); drowDownList.appendTo(drillTypeObj ); drillTypeObj .setAttribute('name', 'DrillType'); } } }
|
Regards,
Ashok
Thanks a lot for the help. That worked flawlessly
Hi Naveen Davuluri,
You are welcome. Get back to
us if you need any further assistance.
Regards,
Ashok
- 3 Replies
- 2 Participants
-
ND Naveen Davuluri
- Jan 6, 2025 04:23 PM UTC
- Jan 8, 2025 03:05 PM UTC