Continuing the discussion from Yet another validator and formatter:
I have just started using this Dependency and it is Fantastic - Thank you @stefano.menci - very helpful
As per the clone link below, I have tried to add the anvil_extras MultiSelectDropDown to the supported list of components for the Validator.required()
method but I can’t seem to get it show the popovers.
Code Snippet
from anvil_extras.popover import popover, pop
from anvil_extras.MultiSelectDropDown import MultiSelectDropDown
for component in [TextBox, TextArea, DatePicker, MultiSelectDropDown]:
component.popover = popover
component.pop = pop
...
def required(self, component, events=None, error_label=None, message='', format='', placement=None):
"""The component must have a value"""
events = events or self._default_events
placement = placement or self._default_placement
def check_this_component(**e):
if type(component) is TextBox:
is_valid = component.text != ''
elif type(component) is DatePicker:
is_valid = component.date is not None
elif type(component) is MultiSelectDropDown: ## New elif added
is_valid = True if component.selected else False ## To cover both [] and None
else:
raise Exception('Unexpected component type: {}'.format(type(component)))
self._set_label(is_valid, component, error_label, message, 'Please enter a value', placement)
return is_valid
self._add_to_all_rules(component, {'validating_function': check_this_component,
'events': events or [],
'error_label': error_label,
'message': message,
'format': format})
The code runs without any errors but does not show the popovers for the MultiSelectDropDowns.
What am I missing here?
Clone Link
Hi Rick,
I’m glad the Validator is helping.
I haven’t looked at the details, but I have tried your code and it works. I added this line to my demo and I do see the popover:
self.validator.required(self.multi_select_drop_down_1,
events=['change'],
placement='left')
I noticed that with placement = 'right'
on the demo, the popover is barely visible on the right of the form.
Perhaps the popover appears outside of the visible area?
The placement of the popovers can be a problem with narrow forms or forms embedded in an alert. And perhaps on mobile platform (I haven’t tried)
Let me know if that’s the problem and you can fix it by changing the side of the popover or if it really doesn’t work.
The Anvil Extra guys have already fixed a couple of problems I reported when I added the popover to the Validator. Now the positioning is a little better, but still not perfect.
Thanks @stefano.menci you are absolutely correct - as per snip below, I didn’t realise the multiselect was not showing fully.
Moving this to the left works. Thank you very much.
Any chance we will see this dependency in anvil_extras?
1 Like
I have proposed it, but @owen.campbell already has plans for a validator with different requirements and perhaps doesn’t want to end up with one library with two partially overlapping modules.
When I saw the post from @hugetim i decided to share it from my own account without a github repository.
I have tried to work with my own cloned copy of Anvil Extras and add my validator to it, then I remembered why I don’t like large dependencies
I used to have my own CustomComponents
dependency that was difficult to maintain and would break many apps if there was a problem. So I split it into many little ones, including this validator, and now the maintenance is much easier.
With my CustomComponents
I used to have dozens of components on the toolbox. Now the toolbox is more compact, but when I use Anvil Extras only for the router I get all those custom components that I don’t need.
I’m back using the official Anvil Extras because it’s well maintained, better than what I would do with my own coy. I think this Validator would belong there, but I don’t know Owens’ long term plans and I’m OK with keeping my little Validator living is own life.
2 Likes
Does not seem to work - I wonder if this is because the parent form is in an alert… I will investigate further.
Just to clarify the Validator is working and returning False but the popover is not visible.
So it looks like with the MultiSelectDropDowns if I move the Validator.required()
method to the form_show
event, it works as expected - even in an alert.
It turns out that this not related to the form_show
event but rather something to do with setting the items of the MultiSelectDropDowns after the Validator.required()
method.
Setting the items first and the the validator
fixes this issue. Thanks very much for your help.
1 Like