Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    RadioButtonGroupItem layout

    Is there a way to layout a form using radio buttons to something like:

    Priority:
    O Low
    O Medium
    O High
    O Other: ________________

    where to the right of "Other:" there would be a text field or dropdown or whatever. Is there a FormItem that is similar to com.google.gwt.user.client.ui.RadioButton that can be used as any other field?

    Thanks!

    #2
    RadioGroupItem layout

    I can imagine 3 ways of accomplishing this:

    1. Use multiple RadioGroupItem items each having 1 radio-button key-value pair; lay out each of the radioGroupItems appropriately adjacent to other form-items; build a change-handler that performs the mutual exclusion around the complete set of RadioGroupItems. This idea seems to have a tremendous overhead.

    2. Use an "absolute" DynamicForm layout. Unsure if radio-buttons of a single RadioGroupItem can be individually laid out agaubst other form-items. Even if this were to work, the power of "table" layout is lost.

    3. Wrap native GWT com.google.gwt.user.client.ui.RadioButton with CanvasItem. Except for having to handle CSS/style issues, this seems like it has the good chance of working.

    Should I be considering other options? TIA!

    Comment


      #3
      Is there a better way ?

      Have a look on the attachement.

      The default to layout options doesn't look nice.

      Can you help me, how to achieve a proper vertical layout.

      e.g.:

      RadioGroup:
      o value 1
      o value 2

      or

      RadioGroup:
      o value 1
      o value 2

      or RadioGroup: o value 1
      o value 2

      In my opinion version 1 looks best.
      Attached Files
      Last edited by damend; 9 Sep 2011, 05:52.

      Comment


        #4
        Set vertical:true for vertical layout. As far as the special problem of having an adjacent test field, sastry's #1 is the right approach, and doesn't have any significant overhead.

        Comment


          #5
          I did the solution #1 and it is overhead, I would say.
          Who is interested, it's something like:

          - mutliple radiobutton groups have to be created with different name
          - placeholderHiddenTextField is needed to save value for form
          - everyone will have :

          @Override
          public void onChange(ChangeEvent changeEventObject) {
          if (changeEventObject.getValue() != null || !changeEventObject.getValue().toString().isEmpty()) {
          placeholderHiddenTextField.setValue(changeEventObject.getValue());
          selectSingleRadioButton(radioChoicer, changeEventObject);
          }
          }


          protected void selectSingleRadioButton(FormItem[] radioChoicer, ChangeEvent eventObject) {
          String radioSelectedName = eventObject.getItem().getName();

          for (int pos = 0; pos < radioChoicer.length - 1; pos++) {
          if (!radioSelectedName.equals(radioChoicer[pos].getName())) {
          radioChoicer[pos].clearValue();
          radioChoicer[pos].redraw();
          }
          }
          }

          Comment


            #6
            I've been trying to implement this, but I can't seem to find any way to detect values being set when a record is loaded from a datasource. You can't override setValue on a FormItem as explained in other threads. I would subclass the DynamicForm, but setValues either isn't called or can't be overridden and I don't see any other useful override points.

            Comment


              #7
              maybe addDataArrivedHandler is helpful

              Comment


                #8
                Only grids have that method, not forms. Did you actually get this working? Did it handle forms being loaded from a datasource?

                Comment


                  #9
                  I finally found a way to make it work. I use setValueFormatter on a hidden field and use that to update the radio groups. Days of work wasted on this...

                  Comment


                    #10
                    For the record, I have also got it to work with an invisible CanvasItem. This is probably a nicer method, being able to use showValue.

                    Comment


                      #11
                      Actually we'd recommend implementing the entire group as a CanvasItem.

                      The DynamicForm would be created with RadioItems for each fixed entry you want to show as well as the "other" radio item and text-box, the showValue handler would be used to set the appropriate item selected (and potentially populate the "other" box), and changed handlers on each item can be used to call 'storeValue' (as well as clearing the other radio items). This would be simple and reusable, and would have the correct logical paradigm (one form item for the field).

                      Comment


                        #12
                        I'm assuming you mean to put the DynamicForm in the CanvasItem. This pretty much returns to the original issue here. The original problem is that RadioGroups mess up the layout of the form, they don't line up with the other items on the form. With my solution, I can now put the radio buttons anywhere on the form. I can use multiple columns *and* multiple rows if I want, or use colspans or rowspans and they all fit in with whatever other items I have on the form.

                        Comment

                        Working...
                        X