Validate Text Area Widget

advanced-prototyping

#1

I am trying to validate a text area widget

for example I type text in this format into the text area and it worked fine

Working format
SELECT * FROM Products WHERE Price BETWEEN 10 AND 20;

But I want to achieve this line break structure
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;

I tried using 2 separate text field like this
Text field 1: SELECT * FROM Products
Text field 2: WHERE Price BETWEEN 10 AND 20;
This works (But I don’t want this) as I will be using tab and its not natural way of typing an SQL Query

I want to be able to type in all the SQL Query in the text area as separate line like this even if it is 20 lines

SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;

Basically I want to achieve this type of structure using only the text area

A Basic Query Structure Looks Like This

SELECT field1 [,“field2”,etc]
FROM table
[WHERE “condition”]
[GROUP BY “field”]
[ORDER BY “field”]

Extra if possible on text change I want to Set text colour of the following( "SELECT, FROM, WHERE, GROUP BY, ORDER BY etc)


Input Field counter and field should change colours and text
#2

Can you upload a screenshot of what you are getting so that we can understand what you mean? It seems you are saying you can’t type line breaks into a Text Area widget, is that right?


#3

Thanks sorry if my question was not clear.

If I type the SQL query as 1 line it works. But if I type it as 2 lines 3 lines etc it does not work

When user type SQL Query its usually best formatted in a way that other users can read and understand it. So I want to achieve that simulation as it will feel more natural typing into the text area.

But I can’t get it to work if I type the SQL query statement with line break even though the texts inside the text area is the same.

See Screenshort


#4

Let’s see if I understand your problem…

  • You want to allow users to enter text in a text area, using line breaks wherever they need.
  • You need to process this text as one long string, thus removing the line breaks–or more accurately, replacing the line breaks with spaces.
  • You want to colorize text based on keywords (or colorize only the keywords?)

You can use the built-in function, replace() to get to one long string, using this algorithm: [[LVAR1.replace("\n"," ")]] where LVAR1 points to your text input widget. You can assign the output to another widget (and hide it if needed) or to a global variable --your choice. Here is a quick demo you can try out:
strip line breaks from text input.rp (47.7 KB)

You won’t be able to set the color or use rich text in an HTML Text Field or Text Area widget. You might be able to fake it by placing a rectangle widget over your text area to obscure it, and in its OnClick event, set the focus to your text area. Then, in the text area’s OnTextChange or OnKeyUp event, set the text on the rectangle to the text on the text area with conditions testing for your keywords (SELECT, FROM, etc.) and using the “rich text” option in the Set Text action. However, my guess is it would work only for the most recent keyword match (where previous keywords would revert to the default text color.)

Hmm… your “fake input widget” could be a repeater, where every time the user presses the Enter key for a line break, a new row is added. Then, in the OnItemLoad event, you could set the color based on recognized keywords. I don’t know how smooth your text entry experience would feel, though.


#5

This is a good solution, But I already have the query result as a Dynamic Panel, so once a user type in the SQL query text = exact match the dynamic panel should display with the prebuilt result

See screenshort


#6

Can’t get it work the way it wanted it to, when I set conditions

if text on queryOutput equals “SELECT * FROM Products WHERE Price BETWEEN 10 AND 20;” it does not work even though i type it like this in queryInput

SELECT * FROM Products

WHERE Price BETWEEN 10 AND 20;

unless I type it like this
SELECT * FROM Products WHERE Price BETWEEN 10 AND 20; (1 row)


#7

Alright this is a video demo of the user typing in there SQL query, so I want the user to type in any form and it should display the dynamic panel


#8

So before you test your conditions, copy the text from the input to either a global variable or a hidden rectangle widget. Then test your conditions using the text on the latter. Make sense?


#9

It is working now, The problem with the text is that it has 1 space when user type like this

SELECT * FROM Products WHERE Price BETWEEN 10 AND 20;

You see space between Products and WHERE, so it does not work

but if I type like
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20; and I move the WHERE UP it closes up the space with the word Products like this

SELECT * FROM ProductsWHERE Price BETWEEN 10 AND 20;

So even though the text is typed like this
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20; (This will work)

But this format does not work
SELECT * FROM Products

WHERE Price BETWEEN 10 AND 20;

I presume is to with how line break is removed

Thanks for you help,


#10

OK… so you want to handle any kind and number of spaces and line breaks, replacing it all with just one space. @josephxbrick and @nkrisc are the string manipulation kings. They might have an elegant solution here. Without regex support, don’t know what it would be…

If it is only 1 or 2 line breaks that you want to replace with one space, I would just do a brute force approach where you first remove two with something like, replace("\n\n", " ") and then a statement to remove one line break from that result with replace("\n", " ").


closed #11

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.