Zod Schema: How to make a field optional OR have a minimum string contraint?

In your case, you consider “” to be the same as undefined (i.e.: when the string is empty, it’s like there’s no string at all). It’s implementable in Zod this way: import { z } from “zod”; import { strict as assert } from “node:assert”; // `myString` is a string that can be either optional … Read more

How do I install JSLint on Ubuntu? [closed]

How to install JSLint on Ubuntu: Install nodejs (includes npm, the Node Package Manager): sudo apt-get install nodejs Install node-jslint. either globally: sudo npm install -g jslint or locally, and include it in $PATH: npm install jslint and add this line to your.bashrc (adjust version number as appropriate) alias jslint=”~/.npm/jslint/0.1.8/package/bin/jslint.js”

remove required property from input field on form submit

JavaScript is case sensitive. Use document.getElementById(“city”).required = false; Demonstration Be careful that your code can’t work as you try to access the element before it exists. Put your script after the element if you don’t execute the code on an event : <input type=”text” id=”city” required> <script> if(somecondition is true){ document.getElementById(“city”).required = false; } </script> … Read more

Do I need to import React for stateless functional components?

Yes, there is. Babel transpiles JSX to use React: <div></div> To: React.createElement(“div”, null); So your JSX is internally transpiled to use React.createElement in pure JavaScript, which does use React. Remember that JSX is just syntactic sugar over pure JavaScript. If you don’t specifically import it, it will report that React isn’t defined. Update Sep 2021: … Read more

Can I run a JS script from another using `fetch`?

Fetch API is supposed to provide promise-based API to fetch remote data. Loading random remote script is not AJAX – even if jQuery.ajax is capable of that. It won’t be handled by Fetch API. Script can be appended dynamically and wrapped with a promise: const scriptPromise = new Promise((resolve, reject) => { const script = … Read more

Prevent select2 from flipping the dropdown upward

Since modifying the source code is not an option and adding a hook to the select2:open event is not very elegant, especially when you have multiple select2 instances in the same page, I have written a small extension for the Select2 plugin. My implementation is inspired by a PR from the plugin’s repository (https://github.com/select2/select2/pull/4618) that … Read more