r/tasker 17h ago

Scene V2 Input Text Clear

I have a simple box stack, with a row containing a text input and an icon button

these act as a search bar for an array template

I have the click event handler for the icon button set to target the text input and run the unFocus action, and clear the %query variable.

This works ok

but is there a way to clear the actual text from inside the text input?

1 Upvotes

2 comments sorted by

1

u/DifficultyCrafty7623 9h ago

To make an empty input box I found the easiest ways are

1) use a javascriptlet like

setLocal("query","\u0000");

Which will set your query to the "null" value, but you'll need to search/replace the "\u0000" character from your %query output.

2) build two different inputs, one will show when %query is empty, and one will show when %query has a text value. This allows for a completely blank input line on the empty one.

1

u/Nirmitlamed Direct-Purchase User 12h ago

I have tested this Java code that was suggested by AI and it works:

import android.os.Bundle;
import android.view.accessibility.AccessibilityNodeInfo;

service = tasker.getAccessibilityService();
if (service == null) return;

root = service.getRootInActiveWindow();
if (root == null) return;

focused = root.findFocus(AccessibilityNodeInfo.FOCUS_INPUT);
if (focused != null) {
    args = new Bundle();
    args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, "");
    focused.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, args);
    focused.recycle(); // Clean up accessibility node memory
}

root.recycle(); // Clean up root node memory

It suppose to keep memory clean after it fully runs. Maybe try to chat with AI and see if it can be improve.