I have a popup window that is going to add machine details in 4 text input component. After adding the data , when I click "add" button, it will add to DB. At the same time it should clear the entered details in the input component. How to achieve that?
I have tried to initialize the component again with empty string, but not working. Please guide me to get this !
Post a nicely cropped screenshot of the view.
Post your code and format it properly. See Wiki - how to post code on this forum.
And the code?
machine_number=self.parent.parent.getChild("Site_SysFlexRepeater").props.instances[0].value
machine_name=self.parent.parent.getChild("Site_SysFlexRepeater").props.instances[1].value
process=self.parent.parent.getChild("Reason_UserFlexRepeater").props.instances[0].value
product=self.parent.parent.getChild("Reason_UserFlexRepeater").props.instances[1].value
ip=self.parent.parent.getChild("Site_SysFlexRepeater_0").props.instances[0].value
if machine_number != '' and machine_name != '' and process != '' and product != '' and ip != '':
system.db.runPrepUpdate("INSERT INTO machine_master (machine_no, machine_name, ipaddress, process,product ) VALUES (?,?,?,?,?)", [machine_number, machine_name, ip, process,product])
self.parent.parent.getChild("Label").props.style.color = '#1E398D'
self.parent.parent.getChild("Label").props.text = "Machine Details Added Successfully"
try:
self.parent.parent.getChild("Site_SysFlexRepeater").props.instances[0].value='';
except:
pass;
else:
self.parent.parent.getChild("Label").props.style.color = '#1E398D'
self.parent.parent.getChild("Label").props.text = "Enter all the Fields"
Onclick Event-Create Button Component
-
Regarding your question title, the Label component is not an input. I suspect you mean the Text Area and Dropdown components.
-
To clear the input components you would have to add a line to clear each field. Something like,
self.parent.parent.getChild("Site_SysFlexRepeater").props.instances[0].value = ''
General comments:
- Form is messy. Vertical alignment is off. Inconsistent capitalisation. Yellow on dark blue button? Could arrange in two columns: labels and inputs.
- The CREATE button should be disabled until all the fields are filled out. Then you don't need the
if ... else ...
stuff. - Using flex repeaters for two components makes life complicated for such a simple form.
- You can avoid all the
parent.parent.getChild
by creating custom properties on the view to hold the input values.- On the view create a custom property for each input value.
- Bind each input to its custom property. Make the binding bidirectional.
- In your code you can now replace
machine_number=self.parent.parent.getChild("Site_SysFlexRepeater").props.instances[0].value
with
machine_number = self.view.custom.machine_num
This is much easier to read and will still work if the path changes when components are moved in and out of containers.
To clear the input field value you would just write to the custom property.
self.view.custom.machine_num = ''
- Consider putting a binding on each input component's border color. Make it red until a valid input has been entered. This is common on web forms.
Thank you for your valuable input. Will correct it.
Having issue. If I add self.parent.parent.getChild("Site_SysFlexRepeater").props.instances[0].value = ' ' like this in inside 'if' condition, I need to again close the popup and open only clearing the data. I need to clear after entering the "Create " Button
The Flex Repeater component might only read parameters on first load. Changing them while open may not work.
Two options:
- Use message handlers.
- Simplify the arrangement and get rid of the flex repeaters.