Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button submit #784

Open
ezeparziale opened this issue Apr 17, 2023 · 2 comments
Open

Button submit #784

ezeparziale opened this issue Apr 17, 2023 · 2 comments
Labels
enhancement New feature, or existing feature improvement

Comments

@ezeparziale
Copy link

ezeparziale commented Apr 17, 2023

Any reason for not having a button element with type="submit"?"

I created a new widget

class Button:
    html_params = staticmethod(html_params)
    validation_attrs = ["required"]

    def __init__(self, input_type=None):
        if input_type is not None:
            self.input_type = input_type

    def __call__(self, field, **kwargs):
        kwargs.setdefault("id", field.id)
        kwargs.setdefault("type", self.input_type)
        flags = getattr(field, "flags", {})
        for k in dir(flags):
            if k in self.validation_attrs and k not in kwargs:
                kwargs[k] = getattr(flags, k)
        return Markup("<button %s>%s</button>" % (self.html_params(name=field.name, **kwargs), field.label.text))

class SubmitButton(Button):
    input_type = "submit"

    def __call__(self, field, **kwargs):
        return super().__call__(field, **kwargs)
    

class SubmitButtonField(BooleanField):
    widget = SubmitButton()
class CreateForm(Form):
    submit = SubmitField("Edit")
    submit_button = SubmitButtonField("Edit")
@azmeuk azmeuk added the enhancement New feature, or existing feature improvement label Jul 21, 2023
@azmeuk
Copy link
Member

azmeuk commented Jul 21, 2023

I think this is simply because submit button became popular more or less recently in the HTML history.

@ThiefMaster
Copy link

type="submit" is already the (not very great) default for a <button> element...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, or existing feature improvement
Development

No branches or pull requests

3 participants