The WTForms documentation on custom widgets is very sparse and gives no hints at how I can achieve what I want. I tried to play with the examples, but that didn't work...
Other questions on stackoverflow don't explain how to develop widgets in general:
All I am looking for is a simple text input field which will contain an URL, with the clickable hyperlink right next to it. So basically, the custom field would only append a hyperlink to the standard input field, which contains its value.
Simple, straightforward examples like this should be in the docs IMHO.
Any instructions or resources explaining how this can be done?
UPDATE: My solution is inelegant but it works...
from wtforms import Field
from wtforms.widgets import TextInput
class MyUrlWidget(TextInput):
def __init__(self):
super(MyUrlWidget, self).__init__()
def _value(self):
if self.data:
return self.data
else:
return ''
def __call__(self, field, **kwargs):
w = super(MyUrlWidget, self).__call__(field, **kwargs)
w = w + '<a href="'+field._value()+'">link</a>'
return w
class MyUrlInput(Field):
widget = MyUrlWidget()
Can anyone help improve this?