Search in sources :

Example 1 with FormField

use of com.willshex.blogwt.client.part.form.FormField in project blogwt by billy1380.

the class FormPart method isValid.

private boolean isValid() {
    boolean isValid = true;
    final int count = pnlFields.getWidgetCount();
    Widget current;
    for (int i = 0; i < count; i++) {
        current = pnlFields.getWidget(i);
        if (current instanceof FormField) {
            if (!((FormField) current).isValid()) {
                isValid = false;
                ((FormField) current).showError();
            } else {
                ((FormField) current).hideError();
            }
        }
    }
    return isValid;
}
Also used : Widget(com.google.gwt.user.client.ui.Widget) FormField(com.willshex.blogwt.client.part.form.FormField)

Example 2 with FormField

use of com.willshex.blogwt.client.part.form.FormField in project blogwt by billy1380.

the class FormPart method onFormSubmit.

@UiHandler("frmForm")
void onFormSubmit(SubmitEvent se) {
    if (isValid()) {
        loading();
        Form form = new Form();
        form.name = name;
        // add fields to form
        final int count = pnlFields.getWidgetCount();
        Widget current;
        Field field;
        for (int i = 0; i < count; i++) {
            current = pnlFields.getWidget(i);
            field = null;
            if (current instanceof FormField) {
                field = new Field().name(((FormField) current).name()).value(((FormField) current).value());
                if (form.fields == null) {
                    form.fields = new ArrayList<Field>();
                }
                form.fields.add(field);
                if (current instanceof TextBoxPart) {
                    field.type(FieldTypeType.FieldTypeTypeText);
                } else if (current instanceof TextAreaPart) {
                    field.type(FieldTypeType.FieldTypeTypeLongText);
                } else if (current instanceof ListBoxPart) {
                    field.type(FieldTypeType.FieldTypeTypeSingleOption);
                } else if (current instanceof ReCaptchaPart) {
                    field.type(FieldTypeType.FieldTypeTypeCaptcha);
                }
            }
        }
        FormController.get().submitForm(form);
    }
    se.cancel();
}
Also used : TextAreaPart(com.willshex.blogwt.client.part.form.TextAreaPart) ListBoxPart(com.willshex.blogwt.client.part.form.ListBoxPart) FormField(com.willshex.blogwt.client.part.form.FormField) UiField(com.google.gwt.uibinder.client.UiField) Field(com.willshex.blogwt.shared.api.datatype.Field) Form(com.willshex.blogwt.shared.api.datatype.Form) TextBoxPart(com.willshex.blogwt.client.part.form.TextBoxPart) Widget(com.google.gwt.user.client.ui.Widget) ReCaptchaPart(com.willshex.blogwt.client.part.form.ReCaptchaPart) FormField(com.willshex.blogwt.client.part.form.FormField) UiHandler(com.google.gwt.uibinder.client.UiHandler)

Aggregations

Widget (com.google.gwt.user.client.ui.Widget)2 FormField (com.willshex.blogwt.client.part.form.FormField)2 UiField (com.google.gwt.uibinder.client.UiField)1 UiHandler (com.google.gwt.uibinder.client.UiHandler)1 ListBoxPart (com.willshex.blogwt.client.part.form.ListBoxPart)1 ReCaptchaPart (com.willshex.blogwt.client.part.form.ReCaptchaPart)1 TextAreaPart (com.willshex.blogwt.client.part.form.TextAreaPart)1 TextBoxPart (com.willshex.blogwt.client.part.form.TextBoxPart)1 Field (com.willshex.blogwt.shared.api.datatype.Field)1 Form (com.willshex.blogwt.shared.api.datatype.Form)1