Hi Tobias,

public  OutputField(String id, IModel<String> model)

something else than String could be possibly too, couldn't it?

>public String getFormId()

I'd prefer #getForm() instead, similar to AjaxButton.

> public List<String> getForIds()

I'd prefer components instead of ids here too (similar to IFormValidator):

    public FormComponent<?>[] getDependentFormComponents()

>private class OutputDefaultAjaxBehavior extends AbstractDefaultAjaxBehavior

I don't see a need for this default behavior - devs will probably have to recalculate the value on the server anyway.

> form1.add(new AttributeAppender("onInput", String.format(...)));

Couldn't that be handled by OutputField automatically? Preferably with event registration instead of an inline event handler?

    public void renderHead(IHeaderResponse response)
    {
        super.renderHead(response);

response.render(OnDomReadyHeaderItem.forScript(String.format("$('#%s').on('input', function() { %s });", getForm().getMarkupId(), getInputScript()));
    }

My 2 cents
Sven


On 01.06.2015 22:35, Tobias Soloschenko wrote:
Hi everyone,

I would like to introduce a new API to make responsive forms available with the HTML5 tag "output".

Information and examples can be found here:

https://github.com/klopfdreh/wicket-components-playground/wiki/14.-HTML5-OutputField-API

Benefits of the OutputField

* Easy client side calculations based on input fields and an AttributeAppender - so the calculation can be changed on server side:

// number1 and number2 are input fields
form.add(new AttributeAppender("onInput", String.format("%s.value=parseFloat(%s.value)+ parseFloat(%s.value)", outputField.getMarkupId(), number1.getMarkupId(), number2.getMarkupId())));

* Automated push of the value to the server side. There the value can be retrieved by get the model of the output field:

form.add(new AjaxButton("submit") {

    private static final long serialVersionUID = 1L;

    @Override
    protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
target.add(label.setDefaultModelObject("The current output value: " + outputField.getDefaultModelObject()));
    }
}.setDefaultFormProcessing(false));

I would be very pleased for any feedback! :-)

kind regards

Tobias

Reply via email to