Define a custom widget class inheriting from whatever widget type your numbers
field defaults to (TextInput
, judging from the tag you're showing) and override its build_attrs
method.
I'd do it something like this:
class SensitiveTextInput(TextInput):
def build_attrs(self, extra_attrs=None, **kwargs):
attrs = super(SensitiveTextInput, self).build_attrs(extra_attrs, **kwargs)
if 'name' in attrs:
attrs['data-encrypted-name'] = attrs['name']
del attrs['name']
return attrs
If you need to do this for more than a handful of widget types you could abstract this into a mixin.