Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Using Tap Forms › A question/problem on “Searching”
- This topic has 7 replies, 3 voices, and was last updated 2 months, 3 weeks ago by John Hamill.
-
AuthorPosts
-
September 22, 2024 at 2:13 PM #51143
John HamillParticipantYouTube has changed one of their settings (the “start at time mark” setting/switch)…
From ‘&t=259s’
To ”#t=259s’I want to find the records in Tapforms matching the old setting/switch. I have made a few attempts at this resulting in 250 records or thereabouts (clearly wrong), but I may not be using “escape special characters” in the correct way (see enclosed screenshots).
Any help would be appreciated.
Regards.
Attachments:
You must be logged in to view attached files.September 22, 2024 at 10:34 PM #51146
Daniel LeuParticipantIf I run into issues with the search, I tend to write a field script:
function Match_T259S() {var field_id = 'fld-xxxx';var field = record.getFieldValue(field_id);const regex = /\&t=259s/g;const found = field.match(regex);return found ? 1: 0;}Match_T259S();Then I create a saved search on that field. You need to adjust the field_id for the field that contains your URL text. The return value of this field script is integer.September 23, 2024 at 6:24 AM #51151
John HamillParticipantThanks for the advice. Will try it and report back.
Regards.
September 25, 2024 at 3:48 AM #51153
John HamillParticipantWorked great, thanks.
One thing for any other users, quotes are required around the regex pattern:
const regex = “/\&t=259s/g”;
September 25, 2024 at 8:15 AM #51154
Daniel LeuParticipantGreat that it works!
Adding quotes around the regex makes it a string and it’s no longer a regex.
September 25, 2024 at 4:27 PM #51155
John HamillParticipantHello Daniel,
I was a bit presumptuous above. I am still having a problem with your script. I have simplified the problem – it may be down to the Javascript ‘match’ function returning an array (true), otherwise returning null, null having its own “difficulties” in Javascript. I have excluded the field id for the present to simplify it. I am still unable to get it working however. Here is my test script:
function Test_Script() {const regex = “/5bq/”;var tstr = “ytube5bq891”;const found = tstr.match(regex);if (found === null)console.log(‘No match’);elseconsole.log(‘Match found’);}Test_Script();September 25, 2024 at 4:34 PM #51156
JScottAParticipantMaybe this response from the ChatGPT Tap Forms 5 Assistant can help you. It is a bit long, but that is how this custom GPT works. I hope it helps:
It seems the user is facing an issue with JavaScript’s
.match()
method and handling null values. Here’s what I can suggest based on their code.### Issues with the Provided Script:
1. **Incorrect Regex Format**: The regular expression is defined as a string ("/5bq/"
). In JavaScript, regular expressions should not be placed inside quotes like that unless explicitly instantiated using theRegExp
constructor. Alternatively, regular expressions can be directly written using the/
delimiter without the need for quotes.2. **Null Handling**: The user is correct that
.match()
returns an array when a match is found andnull
when no match is found. The current handling ofnull
is fine with theif (found === null)
check, but fixing the regex issue should resolve their problem.### Suggested Fix:
Here’s a corrected version of their script:`javascript
function Test_Script() {
const regex = /5bq/; // Corrected regex format
var tstr = “ytube5bq891”;
const found = tstr.match(regex);if (found === null) {
console.log(‘No match’);
} else {
console.log(‘Match found’);
}
}Test_Script();
`
### Explanation:
– **Regex without quotes**: The regular expression/5bq/
is now correctly formatted as a regex object, not a string. JavaScript will treat this as a valid regex pattern and search accordingly.
– **Null Check**: The rest of the code remains the same because the handling ofnull
and matches withif (found === null)
is already correct.### Additional Notes:
– If you want to dynamically create a regex (e.g., from user input), you would use theRegExp
constructor like this:
`javascript
const regex = new RegExp(‘5bq’);
`
This should fix the issue and allow the script to properly check for matches.
For further Tap Forms scripting assistance, you can refer to [Tap Forms Scripting 101](https://www.cattail.nu/tap_forms/tap_forms_scripting_101/index.html). You can also check the scripting section in the Tap Forms documentation around page 53 [oai_citation:1,1328_16794_en_1538683502.pdf](file-service://file-15C3MsaZPdU2JvfF2hiej31w).
You can check more about Tap Forms here: [Tap Forms Assistant](https://chatgpt.com/g/g-aGOEAlajR-tap-forms-5-assistant).
September 25, 2024 at 8:25 PM #51157
John HamillParticipantWell that’s me “looking like a right berk” :)
All working now. Thanks for your help.
-
AuthorPosts
You must be logged in to reply to this topic.