TextField with a Button in a FieldGroup -- best way to achieve this

I’d like to create a TextField widget with a button that will do various lookups in our system and possibly if they select something I’d then update the TextField.

The TextField is used in Forms (and FieldGroups).

Normally, I’d create a CustomComponent and just combine the two, but that component won’t be a Field, and so won’t work in the form.

Do I create a CustomField for this? I’d like the widget to behave as much like a TextField as possible (the actual functionality is only that of a TextField), but with a button I can use to possibly select info from our system to be appended to it. Would my “initContent” return the layout that contains the textfield and button, or just the textfield?

I’d like calls to setValue and getValue and pretty much all other settings to pass through to the TextField as the Button only plays a part in possibly updating the TextField value, but may not. I’m just not sure how best to organize it so my textfield will work “as is” but also have my button linked to it. Thanks for any tips …

Well, no responses, but I can share what I did and it seems to work.

We created a class that extends CustomField since a TextField is a String type field. Our class has a layout, TextField and a button (or in our case, a PopupView).

Per the docs, we added:

@Override
    public Class<? extends String> getType() {
        return String.class;
    }

And this was added to return our layout that contains the TextField and Button/PopupView:

    @Override
    protected Component initContent() {
        return layout;
    }

Less clear was the setInternalValue() class, but we’re using it to just set the TextField’s value:

    @Override
    protected void setInternalValue(String v) {
        textField.setValue(v);
    }

To work in a Form/FieldGroup, we added getValue/setValue/commit/discard to pass these to the TextField:

    @Override
    public String getValue() {
        return textField.getValue();
    }
    @Override
    public void setValue(String v) {
        textField.setValue(v);
    }
    
    @Override
    public void discard() throws Buffered.SourceException {
        textField.discard();
    }
    
    @Override
    public void commit() throws Buffered.SourceException, InvalidValueException {
        textField.commit();
    }

And then we finally added various methods that we use for our TextFields that we also needed to be passed through:

    public void setMaxLength(int maxLength) {
        textField.setMaxLength(maxLength);
    }
    
    public void setInputPrompt(String inputPrompt) {
        textField.setInputPrompt(inputPrompt);
    }
    
    public void setNullRepresentation(String nullRepresentation) {
        textField.setNullRepresentation(nullRepresentation);
    }

    public void setNullSettingAllowed(boolean v) {
        textField.setNullSettingAllowed(v);
    }

Don’t know if this is all correct, but it appears to work well in our forms.