I have a form with a reset button.
In the form there is a text that derived from the inputs and updates using param.watch on each input.
When i click reset i clear all inputs with <input>.value = ''
But this is updating the text on each change.
How can I prevent it?
You should have a look at the batch or discard mechanisms, available with the batch_call_watchers
and discard_events
functions of Param.
Can this be used with inputs in CompositeWidget?
You’ll have to share some code and an example for me to try to reply to that question
1 Like
something like:
class FunctionCreationForm(ScriptingLanguageWidgetBase):
_tags_input = None
_functions_select = None
_duration_input = None
_operators_select = None
_condition_input = None
_expression = None
tag_input_title = 'Tag *'
function_select_title = 'Function'
duration_input_title = 'Duration (min)'
operator_select_title = 'Operator *'
condition_input_title = 'Condition *'
def __init__(self, state, *args, **kwargs):
widget_size = dict(width=150, height=60)
self._tags_input = pn.widgets.MultiChoice(name=self.tag_input_title,
solid=False,
options=state.tags,
max_items=1,
option_limit=5,
**widget_size)
self._functions_select = pn.widgets.Select(name=self.function_select_title,
options=[''] + list(FUNCTIONS),
**widget_size)
self._duration_input = pn.widgets.TextInput(name=self.duration_input_title, **widget_size)
self._operators_select = pn.widgets.Select(name=self.operator_select_title,
options=[''] + list(self.operators),
**widget_size)
self._condition_input = pn.widgets.TextInput(name=self.condition_input_title, **widget_size)
self._expression = ScriptingLanguageExpressionForm(state,
*args,
state_tree_keyword=self.state_tree_keyword,
**kwargs)
super().__init__(state, *args, **kwargs)
self._expression.on_query_change(self._clear_inputs)
self.subscribe_input_events()
self.state.register_events(self.on_tags_change)
def subscribe_input_events(self):
self._tags_input.param.watch(self.create_expression, ['value'])
self._duration_input.param.watch(self.create_expression, ['value_input'])
self._condition_input.param.watch(self.create_expression, ['value_input'])
self._operators_select.param.watch(self.create_expression, ['value'])
self._functions_select.param.watch(self.create_expression, ['value'])
def _clear_inputs(self, *args, **kwargs):
# FIXME prevent all below input from triggering events
self._tags_input.value = []
self._functions_select.value = ''
self._duration_input.value_input = ''
self._operators_select.value = ''
self._condition_input.value_input = ''
self.create_expression()