Hi everyone
I am trying to add a textbox to my form via code and define what happens when the user presses enter on the textbox.
Once the user presses enter a method called FrontLength is meant to run and check if the inserted value is valid according to pre-defined limits on the server. If the number is outside the limits a warning popup should appear
It seems that the number the user inserts is updated every time enter is pressed but the FronLength method only runs once when the form uploads, where it should run every time the user presses enter
What am I doing wrong?
Here is the app:
https://anvil.works/build#clone:CC7UWMLM7YUPSM7E=FOEYRRXVMTVHLJZGZVDA6OWR
Here is the code:
from ._anvil_designer import TestingAddingTextTemplate
from anvil import *
import anvil.server
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables
import TestModule as MD
class TestingAddingText(TestingAddingTextTemplate):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Any code you write here will run before the form opens.
cp = self.column_panel_1
if MD.MainPackage['Components']['Front']:
self.FrontLengthTextBox = TextBox(type='number', align='right')
fp_Front = FlowPanel(align='right')
fp_Front.add_component(Spacer(height=32))
fp_Front.add_component(self.FrontLengthTextBox)
fp_Front.add_component(Label(align = 'right', text='Insert length in cm'))
self.FrontLengthTextBox.set_event_handler("pressed_enter", self.FrontLength())
cp.add_component(fp_Front)
def FrontLength(self, **event_args):
"""This method is called when the user presses Enter in this text box"""
LengthOK = anvil.server.call('LengthAllowanceCalculation', MD.MainPackage['GeneralProjectData']['KitchenShape'], self.FrontLengthTextBox.text, 'Front', MD.MainPackage['GeneralProjectData']['BarMatrix'][0])
if not LengthOK[0]:
t = TextBox(placeholder=f"Insert value bigger than {LengthOK[1]} cm", align = 'Right')
result = alert(content=t, title= "Lenght is too short")
pass
def button_1_click(self, **event_args):
"""This method is called when the button is clicked"""
print('Button clicked, Length value is:', self.FrontLengthTextBox.text)
pass
```