Botpress Validation Function Error: “Cannot read properties of undefined (reading ‘trim’)”

I wrote code in Validation (Advanced Configuration) to validate a Capture Information – Single Choice type. When I clicked on one of the choices I set up before and called the validate function, I got the error:

Error executing validation “inline-vld-8ba292d8e1.js” [Error, Cannot read properties of undefined (reading ‘trim’)]

In my opinion, Botpress called the validation function before the input received a value, leading to this error.

Validation Code (JavaScript):

function validate(input: { value: string }): boolean {
    const normalizedInput = input.value.trim().toLowerCase();
    return ["buy", "rent", "offplan"].includes(normalizedInput);
}

Logs (7 items – 1 error):

[Capture] User clicked on a button, so we are skipping the cognitive extraction  
Executing capture card custom validation  
Error executing validation "inline-vld-8ba292d8e1.js"  
[Capture] Field validation failed. Extracted: "Buy". Input: Buy  
[Capture] Extraction failed (2/2 attempts)  
[Capture] Prompt failed. Maximum number of retries reached.  
[Capture] Prompt failed  

Screenshots:

What I Tried

I modified the code as follows, but the issue persists:

const normalizedInput = input?.value?.trim().toLowerCase() || "";

If I use an Execute Code Card after the Capture Information Card, the value is already stored in a variable, and this issue does not occur. However, if the value is invalid, the user is forced to enter the information from the beginning.

Alternatively, using an Expression Card after each Capture Information Card allows validation without an undefined error, but an invalid value still forces the user to re-enter the information from the start of the node.

Related Screenshot:

Does anyone have a solution to prevent Botpress from triggering the validation function before the input receives a value?

Setting up user id in Google analytics with Google tag (gtag.js)

I have a user set up as follows with Google tag, gtag.js:

<!-- Google tag (gtag.js) -->  
<script async src='https://www.googletagmanager.com/gtag/js?id=G-Lxxxxxxx'></script>
<script>
window.dataLayer = window.dataLayer || [];  
function gtag() {
    dataLayer.push(arguments);
}
gtag('js', new Date()); 
gtag('config', 'G-Lxxxxxxx', {'user_id': 'DRCUSASK'})
</script>

This appears first in the <head> element as it should. However, weeks on, no data is showing up. I have checked and double checked the code. When I go into the admin for this property I see this message:

Data collection isn’t active for your website. If you installed tags more than 48 hours ago, make sure they are set up correctly.

Yet, when I test the site in admin (using the option to set up the property manually) using the ‘Test your website’ option, I get a green tick. I see that in similar questions asked here there can be issues of mismatches between Universal Analytics, GA4 (and even earlier systems) and gtag.js. Both Universal Analytics and GA4 had their own ways of handling user_ids, and I am indeed still using GA4 in older websites, with no problems.

Help, anyone!

Javascript counting checkboxes not working

the following Javascript code works in counting how many checkboxes are checked and highlights the row in orange:

function countCheckboxes() {
    var form = document.getElementById('frmAds');
    var count = 0;
    for (var n = 0; n < form.length; n++) {
      if (form[n].name === `chk[${n+1}]` && form[n].checked) {
        count++;
      }
    }

    document.getElementById('checkCount').innerHTML = " <b>" + count + "</b> rows are checked";
  }



    function toggleColour(obj,col)
    {
        col=col||'transparent'
        var row = findParentRow(obj);
        if (!row.col) row.col=row.style.backgroundColor;
        row.style.backgroundColor = obj.checked ? row.col : col; 
        
        countCheckboxes(); // Update the count when checkbox is clicked
    }
    function findParentRow(obj)
    {
        var tmp = obj.parentNode;
        if(tmp.nodeName.toLowerCase() != "tr")
        {
            tmp = findParentRow(tmp);
        }
        return tmp;
        
        
    }

window.onload = countCheckboxes;
<form action="import.php" enctype="multipart/form-data" method="post" id="frmAds">
  <table>
    <tr>
      <td>
        <input type="checkbox" value="1" name="chk[1]" checked="checked" onClick="toggleColour(this,'#FEAB2F');" />
      </td>
      <td>test 1</td>
    </tr>
    <tr>
      <td>
        <input type="checkbox" value="1" name="chk[2]" checked="checked" onClick="toggleColour(this,'#FEAB2F');" />
      </td>
      <td>test 2</td>
    </tr>
    <tr style="background-color:white;">
                 <td class="bigtext"><input type="checkbox" value="1" name="chk[3]" checked="checked" onClick="toggleColour(this,'#FEAB2F');" /></td>
                 <td class="bigtext">1</td>
                 <td class=" bigtext"><input type="hidden" value="03/28/2025" name="date[1]" />03/28/2025</td>
                 <td class="bigtext"><input type="text" size="56" value="Chase - IN *CARTERS TOWING AND RE" name="desc[1]" maxlength="190" style="border: none; padding: 4px; font-size: 12px;" /></td>
                 <td class="bigtext"><select name="cat[1]"><option value="1" selected="selected">(**NO MATCH**)</option><option value="829">(Work) Hotel Stay</option><option value="818">(Work) Uber and Taxi</option><option value="45">Accountant</option><option value="850">Addon Asset</option><option value="2">Bank Dividends</option><option value="3">Bank Interest</option><option value="16">Business Local Taxes</option><option value="821">Cashback Reward</option><option value="864">Commissions &amp; Fees</option><option value="70">DELETE THIS?</option><option value="55">Dental</option><option value="872">Ebay Items</option><option value="50">Estimated Taxes</option><option value="18">Health Insurance</option><option value="53">Medical Services</option><option value="7">Mobile Internet</option><option value="861">Office Rent</option><option value="78">OTR MEALS - Dining</option><option value="81">OTR Meals - Fast Food</option><option value="855">Personal - Air Travel</option><option value="67">Personal - ATM</option><option value="866">Personal - Bank Fees</option><option value="843">Personal - Bug Prevention</option><option value="75">Personal - Car Insurance</option><option value="845">Personal - Car Loan</option><option value="69">Personal - Car Maintenance</option><option value="847">Personal - Car Upgrades</option><option value="72">Personal - Car Wash</option><option value="66">Personal - Clothing</option><option value="61">Personal - Dining</option><option value="89">Personal - Dry Cleaners</option><option value="92">Personal - Electric Bill</option><option value="84">Personal - Entertainment</option><option value="62">Personal - Fast Food</option><option value="867">Personal - Fundrise Investment</option><option value="60">Personal - Gasoline</option><option value="63">Personal - Groceries</option><option value="64">Personal - Haircuts</option><option value="814">Personal - Home Insurance</option><option value="68">Personal - Home Items</option><option value="863">Personal - Home Maintenance</option><option value="94">Personal - Home Security</option><option value="811">Personal - Interest Payments</option><option value="83">Personal - Landscaping</option><option value="71">Personal - Licenses</option><option value="95">Personal - Local Internet</option><option value="97">Personal - Mailbox</option><option value="844">Personal - Miscellaneous</option><option value="76">Personal - Mortgage</option><option value="876">Personal - Mutual Funds</option><option value="862">Personal - Natural Gas</option><option value="857">Personal - Phone Apps</option><option value="819">Personal - Rental Car</option><option value="65">Personal - Shopping</option><option value="873">Personal - Transfers</option><option value="46">Personal - Trash Disposal</option><option value="851">Personal - Truck Upgrades</option><option value="827">Personal - Uber and Taxi</option><option value="885">Personal - Umbrella</option><option value="93">Personal - Water Bill</option><option value="98">Personal - Web Hosting</option><option value="90">Personal - Wine</option><option value="21">PO Box</option><option value="54">Prescriptions</option><option value="813">Property Taxes</option><option value="822">Refunds</option><option value="874">SBA Loan</option><option value="840">State Permits</option><option value="878">Trailer Repair</option><option value="839">Truck 2290</option><option value="849">Truck DACH</option><option value="824">Truck Fuel</option><option value="836">Truck IFTA</option><option value="830">Truck Insurance</option><option value="875">Truck Lumpers</option><option value="832">Truck Maintenance</option><option value="858">Truck Parking</option><option value="834">Truck Payment</option><option value="831">Truck Repairs</option><option value="838">Truck SCAC</option><option value="826">Truck Software</option><option value="58">Truck Supplies</option><option value="833">Truck Tolls</option><option value="837">Truck UCR</option><option value="825">Truck Wash</option><option value="86">W2 Payroll (After Tax)</option></select></td>
                 <td class="bigtext" nowrap><input type="hidden" value="-350.00" name="amount[1]" /><font color="red">$-350.00</font>
                 </td>
                 
                </tr>
    <tr>
      <td>
        <p id="checkCount"> </p>
      </td>
    </tr>
  </table>
</form>

The weird problem is when I add this code to my main site where all of the rows are like the bottom one, it doesn’t work at all. I manually tried removing everything one by one to see what the problem is, and it seems to work once I delete the select and input fields other than the chk checkbox field. Here is the version that doesn’t work:

function countCheckboxes() {
    var form = document.getElementById('frmAds');
    var count = 0;
    for (var n = 0; n < form.length; n++) {
      if (form[n].name === `chk[${n+1}]` && form[n].checked) {
        count++;
      }
    }

    document.getElementById('checkCount').innerHTML = " <b>" + count + "</b> rows are checked";
  }



    function toggleColour(obj,col)
    {
        col=col||'transparent'
        var row = findParentRow(obj);
        if (!row.col) row.col=row.style.backgroundColor;
        row.style.backgroundColor = obj.checked ? row.col : col; 
        
        countCheckboxes(); // Update the count when checkbox is clicked
    }
    function findParentRow(obj)
    {
        var tmp = obj.parentNode;
        if(tmp.nodeName.toLowerCase() != "tr")
        {
            tmp = findParentRow(tmp);
        }
        return tmp;
        
        
    }

window.onload = countCheckboxes;
<form action="import.php" enctype="multipart/form-data" method="post" id="frmAds">
  <table>
   <tr style="background-color:white;">
                 <td class="bigtext"><input type="checkbox" value="1" name="chk[1]" checked="checked" onClick="toggleColour(this,'#FEAB2F');" /></td>
                 <td class="bigtext">1</td>
                 <td class=" bigtext"><input type="hidden" value="03/28/2025" name="date[1]" />03/28/2025</td>
                 <td class="bigtext"><input type="text" size="56" value="CARTERS" name="desc[1]" maxlength="190" style="border: none; padding: 4px; font-size: 12px;" /></td>
                 <td class="bigtext"><select name="cat[1]"><option value="1" selected="selected">(**NO MATCH**)</option><option value="829">(Work) Hotel Stay</option><option value="818">(Work) Uber and Taxi</option><option value="45">Accountant</option><option value="850">Addon Asset</option><option value="2">Bank Dividends</option><option value="3">Bank Interest</option><option value="16">Business Local Taxes</option><option value="821">Cashback Reward</option><option value="864">Commissions &amp; Fees</option><option value="70">DELETE THIS?</option><option value="55">Dental</option><option value="872">Ebay Items</option><option value="50">Estimated Taxes</option><option value="18">Health Insurance</option><option value="53">Medical Services</option><option value="7">Mobile Internet</option><option value="861">Office Rent</option><option value="78">OTR MEALS - Dining</option><option value="81">OTR Meals - Fast Food</option><option value="855">Personal - Air Travel</option><option value="67">Personal - ATM</option><option value="866">Personal - Bank Fees</option><option value="843">Personal - Bug Prevention</option><option value="75">Personal - Car Insurance</option><option value="845">Personal - Car Loan</option><option value="69">Personal - Car Maintenance</option><option value="847">Personal - Car Upgrades</option><option value="72">Personal - Car Wash</option><option value="66">Personal - Clothing</option><option value="61">Personal - Dining</option><option value="89">Personal - Dry Cleaners</option><option value="92">Personal - Electric Bill</option><option value="84">Personal - Entertainment</option><option value="62">Personal - Fast Food</option><option value="867">Personal - Fundrise Investment</option><option value="60">Personal - Gasoline</option><option value="63">Personal - Groceries</option><option value="64">Personal - Haircuts</option><option value="814">Personal - Home Insurance</option><option value="68">Personal - Home Items</option><option value="863">Personal - Home Maintenance</option><option value="94">Personal - Home Security</option><option value="811">Personal - Interest Payments</option><option value="83">Personal - Landscaping</option><option value="71">Personal - Licenses</option><option value="95">Personal - Local Internet</option><option value="97">Personal - Mailbox</option><option value="844">Personal - Miscellaneous</option><option value="76">Personal - Mortgage</option><option value="876">Personal - Mutual Funds</option><option value="862">Personal - Natural Gas</option><option value="857">Personal - Phone Apps</option><option value="819">Personal - Rental Car</option><option value="65">Personal - Shopping</option><option value="873">Personal - Transfers</option><option value="46">Personal - Trash Disposal</option><option value="851">Personal - Truck Upgrades</option><option value="827">Personal - Uber and Taxi</option><option value="885">Personal - Umbrella</option><option value="93">Personal - Water Bill</option><option value="98">Personal - Web Hosting</option><option value="90">Personal - Wine</option><option value="21">PO Box</option><option value="54">Prescriptions</option><option value="813">Property Taxes</option><option value="822">Refunds</option><option value="874">SBA Loan</option><option value="840">State Permits</option><option value="878">Trailer Repair</option><option value="839">Truck 2290</option><option value="849">Truck DACH</option><option value="824">Truck Fuel</option><option value="836">Truck IFTA</option><option value="830">Truck Insurance</option><option value="875">Truck Lumpers</option><option value="832">Truck Maintenance</option><option value="858">Truck Parking</option><option value="834">Truck Payment</option><option value="831">Truck Repairs</option><option value="838">Truck SCAC</option><option value="826">Truck Software</option><option value="58">Truck Supplies</option><option value="833">Truck Tolls</option><option value="837">Truck UCR</option><option value="825">Truck Wash</option><option value="86">W2 Payroll (After Tax)</option></select></td>
                 <td class="bigtext" nowrap><input type="hidden" value="-350.00" name="amount[1]" /><font color="red">$-350.00</font>
                </td>
                
                </tr><tr style="background-color:white;">
                 <td class="bigtext"><input type="checkbox" value="1" name="chk[2]" checked="checked" onClick="toggleColour(this,'#FEAB2F');" /></td>
                 <td class="bigtext">2</td>
                 <td class=" bigtext"><input type="hidden" value="03/28/2025" name="date[2]" />03/28/2025</td>
                 <td class="bigtext"><input type="text" size="56" value="EXXON" name="desc[2]" maxlength="190" style="border: none; padding: 4px; font-size: 12px;" /></td>
                 <td class="bigtext"><select name="cat[2]"><option value="81" selected="selected">OTR Meals - Fast Food</option><option value="829">(Work) Hotel Stay</option><option value="818">(Work) Uber and Taxi</option><option value="45">Accountant</option><option value="850">Addon Asset</option><option value="2">Bank Dividends</option><option value="3">Bank Interest</option><option value="16">Business Local Taxes</option><option value="821">Cashback Reward</option><option value="864">Commissions &amp; Fees</option><option value="70">DELETE THIS?</option><option value="55">Dental</option><option value="872">Ebay Items</option><option value="50">Estimated Taxes</option><option value="18">Health Insurance</option><option value="53">Medical Services</option><option value="7">Mobile Internet</option><option value="861">Office Rent</option><option value="78">OTR MEALS - Dining</option><option value="81">OTR Meals - Fast Food</option><option value="855">Personal - Air Travel</option><option value="67">Personal - ATM</option><option value="866">Personal - Bank Fees</option><option value="843">Personal - Bug Prevention</option><option value="75">Personal - Car Insurance</option><option value="845">Personal - Car Loan</option><option value="69">Personal - Car Maintenance</option><option value="847">Personal - Car Upgrades</option><option value="72">Personal - Car Wash</option><option value="66">Personal - Clothing</option><option value="61">Personal - Dining</option><option value="89">Personal - Dry Cleaners</option><option value="92">Personal - Electric Bill</option><option value="84">Personal - Entertainment</option><option value="62">Personal - Fast Food</option><option value="867">Personal - Fundrise Investment</option><option value="60">Personal - Gasoline</option><option value="63">Personal - Groceries</option><option value="64">Personal - Haircuts</option><option value="814">Personal - Home Insurance</option><option value="68">Personal - Home Items</option><option value="863">Personal - Home Maintenance</option><option value="94">Personal - Home Security</option><option value="811">Personal - Interest Payments</option><option value="83">Personal - Landscaping</option><option value="71">Personal - Licenses</option><option value="95">Personal - Local Internet</option><option value="97">Personal - Mailbox</option><option value="844">Personal - Miscellaneous</option><option value="76">Personal - Mortgage</option><option value="876">Personal - Mutual Funds</option><option value="862">Personal - Natural Gas</option><option value="857">Personal - Phone Apps</option><option value="819">Personal - Rental Car</option><option value="65">Personal - Shopping</option><option value="873">Personal - Transfers</option><option value="46">Personal - Trash Disposal</option><option value="851">Personal - Truck Upgrades</option><option value="827">Personal - Uber and Taxi</option><option value="885">Personal - Umbrella</option><option value="93">Personal - Water Bill</option><option value="98">Personal - Web Hosting</option><option value="90">Personal - Wine</option><option value="21">PO Box</option><option value="54">Prescriptions</option><option value="813">Property Taxes</option><option value="822">Refunds</option><option value="874">SBA Loan</option><option value="840">State Permits</option><option value="878">Trailer Repair</option><option value="839">Truck 2290</option><option value="849">Truck DACH</option><option value="824">Truck Fuel</option><option value="836">Truck IFTA</option><option value="830">Truck Insurance</option><option value="875">Truck Lumpers</option><option value="832">Truck Maintenance</option><option value="858">Truck Parking</option><option value="834">Truck Payment</option><option value="831">Truck Repairs</option><option value="838">Truck SCAC</option><option value="826">Truck Software</option><option value="58">Truck Supplies</option><option value="833">Truck Tolls</option><option value="837">Truck UCR</option><option value="825">Truck Wash</option><option value="86">W2 Payroll (After Tax)</option></select></td>
                 <td class="bigtext" nowrap><input type="hidden" value="-4.63" name="amount[2]" /><font color="red">$-4.63</font>
                </td>
                
                </tr><tr style="background-color:white;">
                 <td class="bigtext"><input type="checkbox" value="1" name="chk[3]" checked="checked" onClick="toggleColour(this,'#FEAB2F');" /></td>
                 <td class="bigtext">3</td>
                 <td class=" bigtext"><input type="hidden" value="03/28/2025" name="date[3]" />03/28/2025</td>
                 <td class="bigtext"><input type="text" size="56" value="VTC SERVICE" name="desc[3]" maxlength="190" style="border: none; padding: 4px; font-size: 12px;" /></td>
                 <td class="bigtext"><select name="cat[3]"><option value="1" selected="selected">(**NO MATCH**)</option><option value="829">(Work) Hotel Stay</option><option value="818">(Work) Uber and Taxi</option><option value="45">Accountant</option><option value="850">Addon Asset</option><option value="2">Bank Dividends</option><option value="3">Bank Interest</option><option value="16">Business Local Taxes</option><option value="821">Cashback Reward</option><option value="864">Commissions &amp; Fees</option><option value="70">DELETE THIS?</option><option value="55">Dental</option><option value="872">Ebay Items</option><option value="50">Estimated Taxes</option><option value="18">Health Insurance</option><option value="53">Medical Services</option><option value="7">Mobile Internet</option><option value="861">Office Rent</option><option value="78">OTR MEALS - Dining</option><option value="81">OTR Meals - Fast Food</option><option value="855">Personal - Air Travel</option><option value="67">Personal - ATM</option><option value="866">Personal - Bank Fees</option><option value="843">Personal - Bug Prevention</option><option value="75">Personal - Car Insurance</option><option value="845">Personal - Car Loan</option><option value="69">Personal - Car Maintenance</option><option value="847">Personal - Car Upgrades</option><option value="72">Personal - Car Wash</option><option value="66">Personal - Clothing</option><option value="61">Personal - Dining</option><option value="89">Personal - Dry Cleaners</option><option value="92">Personal - Electric Bill</option><option value="84">Personal - Entertainment</option><option value="62">Personal - Fast Food</option><option value="867">Personal - Fundrise Investment</option><option value="60">Personal - Gasoline</option><option value="63">Personal - Groceries</option><option value="64">Personal - Haircuts</option><option value="814">Personal - Home Insurance</option><option value="68">Personal - Home Items</option><option value="863">Personal - Home Maintenance</option><option value="94">Personal - Home Security</option><option value="811">Personal - Interest Payments</option><option value="83">Personal - Landscaping</option><option value="71">Personal - Licenses</option><option value="95">Personal - Local Internet</option><option value="97">Personal - Mailbox</option><option value="844">Personal - Miscellaneous</option><option value="76">Personal - Mortgage</option><option value="876">Personal - Mutual Funds</option><option value="862">Personal - Natural Gas</option><option value="857">Personal - Phone Apps</option><option value="819">Personal - Rental Car</option><option value="65">Personal - Shopping</option><option value="873">Personal - Transfers</option><option value="46">Personal - Trash Disposal</option><option value="851">Personal - Truck Upgrades</option><option value="827">Personal - Uber and Taxi</option><option value="885">Personal - Umbrella</option><option value="93">Personal - Water Bill</option><option value="98">Personal - Web Hosting</option><option value="90">Personal - Wine</option><option value="21">PO Box</option><option value="54">Prescriptions</option><option value="813">Property Taxes</option><option value="822">Refunds</option><option value="874">SBA Loan</option><option value="840">State Permits</option><option value="878">Trailer Repair</option><option value="839">Truck 2290</option><option value="849">Truck DACH</option><option value="824">Truck Fuel</option><option value="836">Truck IFTA</option><option value="830">Truck Insurance</option><option value="875">Truck Lumpers</option><option value="832">Truck Maintenance</option><option value="858">Truck Parking</option><option value="834">Truck Payment</option><option value="831">Truck Repairs</option><option value="838">Truck SCAC</option><option value="826">Truck Software</option><option value="58">Truck Supplies</option><option value="833">Truck Tolls</option><option value="837">Truck UCR</option><option value="825">Truck Wash</option><option value="86">W2 Payroll (After Tax)</option></select></td>
                 <td class="bigtext" nowrap><input type="hidden" value="-1970.07" name="amount[3]" /><font color="red">$-1970.07</font>
                </td>
                
                </tr>
    <tr>
      <td>
        <p id="checkCount"> </p>
      </td>
    </tr>
  </table>
</form>

Any idea how to fix this?

MUI v5 Autocomplete. How to dynamically define argument type in onChange callback based on disableClearable?

I am trying to define reusable Autocomplete component with MUI Autocomplete as a foundation.

I want to define my own onChange callback (for a property) that accepts:

  • string if DisableClearable is true
  • string | null if DisableClearable is false

Each predefined option is object with 2 fields:
{ label: string, value: string }

So I assume that onChange value maybe be Value | string | null

  • Value – object is label and value
  • string – if freeSolo
  • null – if DisableClearable false

Here is my onChange:

      onChange={(_, value: Value | string | null) => {
        onChange((typeof value === 'string' ? value : value?.value) || null);
      }}

That worked perfectly while DisableClearable was always false
But now I define DisableClearable generic

export type AutocompleteProps<
  Value extends LabelValuePair,
  FreeSolo extends boolean,
  DisableClearable extends boolean,
> = Omit<
  MuiAutocompleteProps<Value, false, DisableClearable, FreeSolo>,
  | 'renderInput'
  | 'onChange'
  | 'multiple'
  | 'autoSelect'
  | 'selectOnFocus'
  | 'clearOnBlur'
  | 'handleHomeEndKeys'
> & {
  error?: boolean;
  onChange: (value: DisableClearable extends true ? string : string | null) => void;
};

And now for

onChange={(_, value: Value | string | null) => {
        onChange((typeof value === 'string' ? value : value?.value) || null);
      }}

I receive TS error:

TS2345: Argument of type string | null is not assignable to parameter of type
DisableClearable extends true ? string : string | null
Type null is not assignable to type
DisableClearable extends true ? string : string | null

So I wonder how to resolve this issue and allow ts to infer type of onChange dynamically

I expect that I can pass to the component:
(value: string) => void if DisableClearable is true
(value: string | null) => void if DisableClearable is false

Here is full component:

export type AutocompleteProps<
  Value extends LabelValuePair,
  FreeSolo extends boolean,
  DisableClearable extends boolean,
> = Omit<
  MuiAutocompleteProps<Value, false, DisableClearable, FreeSolo>,
  | 'renderInput'
  | 'onChange'
  | 'multiple'
  | 'autoSelect'
  | 'selectOnFocus'
  | 'clearOnBlur'
  | 'handleHomeEndKeys'
> & {
  error?: boolean;
  onChange: (
    value: DisableClearable extends true ? string : string | null,
  ) => void;
};

export const Autocomplete = <
  Value extends LabelValuePair,
  FreeSolo extends boolean,
  DisableClearable extends boolean,
>({
  error,
  onChange,
  freeSolo,
  value,
  ...props
}: AutocompleteProps<Value, FreeSolo, DisableClearable>) => {
  const freeSoloParams = freeSolo
    ? {
        selectOnFocus: true,
        clearOnBlur: true,
        handleHomeEndKeys: true,
      }
    : {};

  // we are trying to find selected option in options otherwise using value (for example when free solo)
  const selectedValue = useMemo(
    () => props.options.find((option) => option.value === value) || value,
    [props.options, value],
  );

  return (
    <MuiAutocomplete
      {...props}
      {...freeSoloParams}
      value={selectedValue}
      filterOptions={(options, params) => {
        const filter = createFilterOptions<Value>();
        const filtered = filter(options, params);

        if (!freeSolo) {
          return filtered;
        }

        const { inputValue } = params;
        const isExisting = options.some(
          (option) => inputValue === option.label,
        );
        if (inputValue && !isExisting) {
          filtered.push({
            value: inputValue,
            label: `Add "${inputValue}"`,
          } as Value);
        }

        return filtered;
      }}
      freeSolo={freeSolo}
      onChange={(_, value: Value | string | null) => {
        onChange((typeof value === 'string' ? value : value?.value) || null);
      }}
      renderInput={(params) => <Input {...params} error={error} />}
    />
  );
};

Can I capture an external async function unhandled error?

Let’s suppose I want to use an async function foo from an external library, which calls another async function bar that throws an error that foo does not handle:

// External library code (non-modifiable)

async function bar(){
  throw Error("Error example");
}

async function foo() {
  bar()
}

If in my code I want to use foo, is there any way I can handle the error thrown by bar? This does not work, as foo does not await for bar:

// My code

async function myMain(){
  try {
    await foo();
  } catch (error) {
    console.log("Error captured in myMain:", error.message);
  }
}

How to get fields name dynamically in row of element plus table?

In Laravel 12 / vuejs 33.5.13 / element-plus 2.9.5 app I have a table with dynamic columns in labels array like :

    <el-table :data="items" style="width: 100%"
              :row-class-name="tableRowClassName"
              :header-row-class-name="headerRowClassName"
    >
        <el-table-column label="ID" prop="id"></el-table-column>
        ...

<!--        create dynamic list of columns  -->
        <el-table-column v-for="(label, index) in labels" v-if="labels"
                         :key="label.title_field"
                         :prop="label.value_field"
                         label="Label Text"
                         :min-width="80">
        </el-table-column>


    </el-table>

I found branch Background colors to rows of a element-ui table with pagination in vueJS 2 but failing to render
and I to make in similar way but I do not know how can I refer to column name dynamically, as any row has columns like :

labels_length
item_1_value
item_2_value
item_3_value

and method :

methods: {

    tableRowClassName({row, rowIndex}) {
        for (let i=0;i< row.labels_length;i++) { //
            if(100 < parseInt(row.getFieldValueByName['item_'+i+'_value'])) {
                return 'warning-row-class';
            }
        }

The row var has no any method like getFieldValueByName and I wonder in which way I can get fields name dynamically ?

Screen Orientation Lock

I’m working on a small project in order to learn TS/JS and Pixi JS. And came up with the following problem I cannot find the solution (or, at least, explanation) for.

Per the reference, there is the lock() method for the screen orientation. However, when I try to use it, I get the error TS2339: Property 'lock' does not exist on type 'ScreenOrientation'. in VS Code during the build stage. Moreover, the VS Code‘s drop-down menu doesn’t list the lock() method. However, it provides the unlock() method.

VS Code

Question: How to fix that issue?

Javascript stops working after changing table with Intraweb [duplicate]

I made a small Intraweb program with a HTML template. In Delphi I fill a table with data. When clicking the table the selected row lights up, as per the JS code. When I refill the table the script stops working and the selected line does not light up. Other elements stay working.

Can anyone tell me why this is happening?

<div class="split right">
  {%lPosten%}<br><br><br><br>
</div>

<style>
 .Kies {background-color: rgb(241, 198, 132);}
</style>

<script>
  $('#Posten td').click(function () {
    var k = $(this);
    k.closest("table").find("tr.Kies").removeClass("Kies");
    k.closest("tr").addClass("Kies");

    ajaxCall("LeesRegel", "Params=" + k.closest("tr").attr('ID'))
  });
</script>

Javascript event queue execution order.. Please give the o/p of gthe snippet with reasoning

I have come again with a new code snippet..Please predict the o/p along with the event queue reasoning..i ran the snippet and i know the o/p but i just want to understand the event queue working and what gets higher preference and logs first..

Seems like some people got offended by my last POST .I had just asked for an explanation how the internals of event queue works in that particular code snippet..

Anyways here is the new snippet..

console.log("Start");

setTimeout(() => console.log("Timeout 1"), 0);

async function asyncFunc() {
  console.log("Async Start");
  await new Promise((resolve) => setTimeout(() => resolve(), 0));
  console.log("Async End");
}

asyncFunc();
Promise.resolve().then(() => console.log("Promise 1"));
setTimeout(() => console.log("Timeout 2"), 0);
console.log("End");

Please predict the o/p along with your reasoning.. for the order (microtask queue, callback queue)

Thanks in advance…

Why Is My /users/search Route Being Treated as “:id” of /users/:id in Express.js? [closed]

NOTE: I’m not very good at English, but I’ll try to keep things clear.

I am currently learning Express.js and have covered topics like creating routes, middleware, and express-validators—not too much, just at a beginner level to understand how they work.

I know how to use query validators from express-validator. Initially, I was hardcoding the validation directly in the route, but then I thought of using it as middleware to handle multiple filters. So, I created a function and started using it. The searching and filtering still worked, but my code started to look messy. To improve structure, I moved the query validation logic to a separate file and imported my function from there. That’s when the problem started.

I’ve uploaded the repo to GitHub so you can check it out:
Repo link: Express_Learning

The Issue:

The route is returning an unexpected error that shouldn’t be caused by the filtering logic in my GET /users/search?filterBy=""&value="" route.

After analyzing my code, I realized that my /users/:id route might be interpreting filterBy as :id. I have a condition in my /users/:id route that throws an error { msg: "Provide a valid ID" } if id is NaN. This error is being thrown when calling /users/search, even though that route has nothing to do with id.

I asked ChatGPT, and it suggested that the issue is due to the order of my routes. It recommended placing the /users/search?filterBy=""&value="" route above the /users/:id route.

Can someone explain why this happens?

Trying to create a preview with stimulus doesn’t work in Rails

I am trying to add a preview when uploading an image, and I’ve came across this tutorial:
“Image Previews with Active Storage in Ruby on Rails 7”

I followed every step but I realized that the stimulus connect function is never called. I don’t have any errors in the console, it just doesn’t work.
I’ve tried reinstalling the stimulus but it didn’t worked.

HTML

<div data-controller = "previews">
<%= form.file_field :image, direct_upload: true, data: { previews_target: "input", action: "change->previews#preview"}, class:"form-control" %>

<% if movie.image.attached? %>
    <%= image_tag movie.image, data: { previews_target: "preview"}, class: "image-cover-preview" %>
<% else %>
    <%= image_tag "", data: { previews_target: "preview"}, class: "image-cover-preview" %>
<% end %>

JS

import { Controller } from "@hotwired/stimulus"


export default class extends Controller 
{
  static targets = ["input", "preview"];

  connect() 
  {
    console.log("THIS IS A PREVIEW", this.element);
  }

  preview()
  {
    let input = this.inputTarget;
    let preview = this.previewTarget;
    let file = input.files[0];
    let reader = new FileReader();
reader.onloadend = function()
{
  preview.src = reader.result;
};

if(file)
{
  reader.readAsDataURL(file);
}
else
{
  preview.src = "";
}
  }
}

Scraping a Gamma site and hosting it on Hostinger [closed]

I’m trying to scrape this page: https://digital-dynamo-1txmi5g.gamma.site/ (built with Gamma) and upload it to public_html on Hostinger. However, I encountered issues with images, animations, and responsiveness.

How can I scrape and host the page while preserving images, animations, and responsiveness? Any suggestions?

Here’s what I tried:

  • Save as “Web Page, Complete” – The page breaks (missing images, animations, incorrect layout).

  • DevTools > Save as “HTML only” (mobile version) – The mobile version works, but the desktop one doesn’t.

  • Puppeteer (Node.js) – Same results as “HTML only”.

server page showing cannot find ejs module

i have already installed ejs in my mac terminal but when i m running the project the server page showing cannot find ejs module
anyone knows how to resolve it and i have also done reinstalling ejs , restarting the server , checking node module (dont suggest these methods)
pls suggest some

Server error in different browsers when i use my local server – cors [duplicate]

I am writing and testing a full-stack application. My frontend is uploaded to hosting and has the address for example – planner. And my server is on a local computer with a database. For the test, I run the server through the ngrok tunnel, I registered, and received a free static domain for example – grateful.
In requests, I use axios, I have public requests – $public, and authorized with a token – $auth. Public requests work without problems, but for requests with authorization I get a CORS error. This error is in both desktop Google Chrome and mobile Google Chrome, in Microsoft Edge, and also in Safari on the iPhone.
My CORS ERROR is: cross-origin resource sharing error wildcard origin not allowed


I am sending next code

  1. axios request settings
  2. CORS settings on the server
  3. as well as responses in the Google Chrome browser to an authorized request, as well as the response from the Microsoft Edge browser.

  1. const $auth = axios.create({
    baseURL: “grateful”,
    withCredentials: true,
    });
    const $public = axios.create({
    baseURL: “grateful”,
    withCredentials: true,
    });

    $auth.interceptors.request.use((config) => {
    config.headers.Authorization = Bearer ${localStorage.getItem( "accessTokenPlanner" )};
    return config;
    });

  2. const allowedOrigins = [
    “planner”,
    “grateful”,
    ];

    app.use(
    cors({
    origin: function (origin, callback) {
    if (!origin || allowedOrigins.includes(origin)) {
    callback(null, true);
    } else {
    callback(new Error(“CORS not allowed”));
    }
    },
    credentials: true,
    methods: [“GET”, “POST”, “PUT”, “DELETE”, “OPTIONS”],
    allowedHeaders: [“Content-Type”, “Authorization”],
    })
    );

    app.options(“*”, cors());

3)

Google chrome
access-control-allow-origin: *
content-length: 2906
content-security-policy: default-src 'self' https://cdn.ngrok.com 'unsafe-eval' 'unsafe-inline'; img-src data: w3.org/svg/2000
content-type: text/html
date: Thu, 27 Mar 2025 14:43:11 GMT
referrer-policy:no-referrer
x-content-type-options:nosniff
----
MS Edge
access-control-allow-origin:*
content-length:2906
content-security-policy:default-src 'self' https://cdn.ngrok.com 'unsafe-eval' 'unsafe-inline'; img-src data: w3.org/svg/2000
content-type:text/html
date:Thu, 27 Mar 2025 15:31:51 GMT
referrer-policy:no-referrer
x-content-type-options:nosniff

I checked all the link addresses and rewrote the settings several times.
The most interesting thing is that with these settings that I wrote above, everything works periodically in the desktop version of Google Chrome. But now it doesn’t work anymore, although I didn’t change anything.