You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

QOOXDOO框架:如何在表单Account number文本框旁添加功能按钮

Hey there! Since you're new to Qooxdoo, let's walk through exactly how to add those two small search buttons next to your Account number TextField—this is totally doable with Qooxdoo's flexible layout system and component library.

Step 1: Ditch the auto-renderer for manual form rows (most flexible approach)

Since you're using a single-column renderer right now, it's easier to build each form row manually. This lets you freely add extra components like your search buttons without fighting the renderer's default structure. Here's a complete, working example:

// Create the main container for your form (vertical layout with spacing)
const mainFormContainer = new qx.ui.container.Composite(new qx.ui.layout.VBox(10));
mainFormContainer.setPadding(20);

// --------------------------
// Build the Account Number row (with search buttons)
// --------------------------
const accountLabel = new qx.ui.basic.Label("Account number");
accountLabel.setWidth(120); // Fixed width to align all labels neatly
accountLabel.setAlignY("middle");

// Container for the text field + buttons (horizontal layout)
const accountInputWrapper = new qx.ui.container.Composite(new qx.ui.layout.HBox(5));
const accountNumberField = new qx.ui.form.TextField();
accountNumberField.setPlaceholder("Enter account or name");
accountInputWrapper.add(accountNumberField, { flex: 1 }); // Let text field take remaining space

// Create the two small search buttons (using icons for compactness)
const searchByAccountBtn = new qx.ui.form.Button(null, "@MaterialIcons/search/16");
searchByAccountBtn.setToolTipText("Search by account number");
searchByAccountBtn.addListener("execute", () => {
  const searchValue = accountNumberField.getValue().trim();
  if (!searchValue) {
    qx.ui.dialog.Dialog.error("Please enter an account number to search");
    return;
  }
  // Replace this with your actual account search logic
  console.log(`Searching for account: ${searchValue}`);
});

const searchByNameBtn = new qx.ui.form.Button(null, "@MaterialIcons/person/16");
searchByNameBtn.setToolTipText("Search by name");
searchByNameBtn.addListener("execute", () => {
  const searchValue = accountNumberField.getValue().trim();
  if (!searchValue) {
    qx.ui.dialog.Dialog.error("Please enter a name to search");
    return;
  }
  // Replace this with your actual name search logic
  console.log(`Searching for name: ${searchValue}`);
});

// Add buttons to the input wrapper
accountInputWrapper.add(searchByAccountBtn);
accountInputWrapper.add(searchByNameBtn);

// Combine label and input wrapper into a single row
const accountRow = new qx.ui.container.Composite(new qx.ui.layout.HBox(10));
accountRow.add(accountLabel);
accountRow.add(accountInputWrapper, { flex: 1 });
mainFormContainer.add(accountRow);

// --------------------------
// Add your other form fields (Name, Cell number) using the same pattern
// --------------------------
const nameLabel = new qx.ui.basic.Label("Name");
nameLabel.setWidth(120);
nameLabel.setAlignY("middle");
const nameField = new qx.ui.form.TextField();
const nameRow = new qx.ui.container.Composite(new qx.ui.layout.HBox(10));
nameRow.add(nameLabel);
nameRow.add(nameField, { flex: 1 });
mainFormContainer.add(nameRow);

const cellLabel = new qx.ui.basic.Label("Cell number");
cellLabel.setWidth(120);
cellLabel.setAlignY("middle");
const cellField = new qx.ui.form.TextField();
const cellRow = new qx.ui.container.Composite(new qx.ui.layout.HBox(10));
cellRow.add(cellLabel);
cellRow.add(cellField, { flex: 1 });
mainFormContainer.add(cellRow);

// Add the entire form to your app's root container
this.getRoot().add(mainFormContainer, { edge: 0 });

Key Details to Note:

  • Layouts: We use HBox for horizontal alignment (label + input + buttons) and VBox for vertical alignment of form rows—this keeps everything clean and responsive.
  • Compact Buttons: Using icons (via Qooxdoo's built-in Material Icons) instead of text makes the buttons small and unobtrusive, just like you wanted. The tooltips let users know what each button does.
  • Input Validation: We added quick checks to ensure users enter a value before searching—you can expand this with more robust validation if needed.

If You Insist on Using the Single-Column Renderer

If you don't want to rebuild your form manually, you can hack into the renderer's existing rows, but this is less reliable (since renderer internals might change between Qooxdoo versions):

// Assume you have your existing form and renderer set up
const form = new qx.ui.form.Form();
const accountNumberField = new qx.ui.form.TextField();
form.add(accountNumberField, "Account number");
// ... add other fields ...

const renderer = new qx.ui.form.renderer.Single(form);
mainFormContainer.add(renderer);

// Get the first row (your Account number row)
const accountRow = renderer.getLayout().getChildren()[0];
// Get the container holding the text field (second child of the row)
const inputContainer = accountRow.getChildren()[1];
inputContainer.setLayout(new qx.ui.layout.HBox(5));

// Add your buttons here (same button code as above)
inputContainer.add(searchByAccountBtn);
inputContainer.add(searchByNameBtn);

I'd strongly recommend the manual form row approach though—it's more maintainable and gives you full control over your UI.

内容的提问来源于stack exchange,提问作者Lauren Kay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:25:49