What highlighting method is used to indicate invalid input in Dojo's ValidationTextArea widgets?

I am in the process of developing a unique Dojo ValidationIdBox widget that extends from ValidationTextBox. The main feature of my custom widget is that it includes asynchronous duplicate ID verification with a backend server.

By extending dijit.form.ValidationTextBox and making adjustments to the isValid() and validate() methods, I have encountered an issue with the validation behavior. While the widget successfully detects and alerts missing required input or a duplicate ID (with the tooltip showing), it fails to highlight the field as expected.

To diagnose the problem, I have created a simplified code snippet below that closely resembles the original Dojo code with minor modifications. My approach involves running standard ValidationTextBox validation first, followed by a check for duplicate IDs. Currently, the uniqueness test intentionally returns failure.

Similarly, I have made changes to the validate() method to perform normal validation before additional processing if the regular validation passes but the uniqueness validation fails. Although I attempted to replicate the same styling logic used when the ValidationTextBox is in error state, the visual effects do not match up: The 'ID not available' tooltip appears, yet the red outline with an exclamation mark does not display.

While examining ValidationTextBox's source code, I was unable to discern how the specific styling triggers work... Can anyone provide insight into how ValidationTextArea operates? In particular, I am unsure about the utilization of this._maskValidSubsetError, aria-invalid, and this.state.

(Additionally, there are instances where I want the tooltip to appear without the red styling, such as during AJAX duplicate ID check request processing.)

// If ValidationTextBox Validates
isValid: function(isFocused, requireUnique) {
    if (typeof requireUnique === 'undefined') requireUnique = false;

    var isValid = this.inherited(arguments);
    var isUnique = false;

    return (requireUnique ? (isValid && isUnique) : isValid);
},

validate: function(/*Boolean*/ isFocused){
    // summary:
    //        Called by on init, on blur, and on keypress.
    // description:
    //        Show missing or invalid messages if appropriate, and highlight the textbox field.
    // tags:
    //        protected

    var message = "";
    var isValid = this.disabled || this.isValid(isFocused);

    if(isValid){ 
        this._maskValidSubsetError = true; 
    }

    var isEmpty = this._isEmpty(this.textbox.value);
    var isValidSubset = !isValid && isFocused && this._isValidSubset();
    
    this._set("state", isValid ? "" : (((((!this._hasBeenBlurred || isFocused) && isEmpty) || isValidSubset) && this._maskValidSubsetError) ? "Incomplete" : "Error"));
    
    this.focusNode.setAttribute("aria-invalid", isValid ? "false" : "true");

    if(this.state == "Error"){
        this._maskValidSubsetError = isFocused && isValidSubset;
        message = this.getErrorMessage(isFocused);
    }else if(this.state == "Incomplete"){
        message = this.getPromptMessage(isFocused); 
        this._maskValidSubsetError = !this._hasBeenBlurred || isFocused; 
    }else if(isEmpty){
        message = this.getPromptMessage(isFocused);
    }

    /// Begin custom widget code
    if (isValid && !this.isValid(isFocused, true)) {
        isValid = false;

        var isValidSubset = !isValid && isFocused && this._isValidSubset();

        this._maskValidSubsetError = isFocused && isValidSubset;
        message = 'ID not available';

        this.focusNode.setAttribute("aria-invalid", isValid ? "false" : "true");
    }
    /// End custom widget code

    this.set("message", message);
    return isValid;
},

Answer №1

It's possible that the answer is eluding you, hidden within a tangle of inline code logic.

The purpose of the blur/keypress mechanism is to ensure that the tooltip is only displayed on the currently active box, indicated by _maskValid.

Have you experimented with

this.set("state", this.isUnique() ? "" : "Error");
yet?

Widgets have their own state and using .set could potentially solve the issue, triggering an event or publishing a topic.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

If I remove my project but still have it saved on my GitHub, do I need to reinstall all the dependencies or can I simply run npm install again?

I have a question regarding my deleted project that is saved on GitHub. If I formatted my PC and lost the project but it's still on GitHub, do I need to reinstall all the dependencies or can I just run 'npm install'? The project has dependen ...

What could be the reason for express-validator's inability to identify missing fields during the validation of XML input

My server, based on Express, is set up to parse XML instead of JSON using body-parser-xml. To validate the input body, I am using express-validator as shown in the following simplified example: router.post("/", body('session.credential[0].$.usern ...

Effortless script to make a URL request and display the response status | using JavaScript with jQuery

Is there a way to use JavaScript or jQuery to request a URL or website address and display the response code? For example: request www.google.com if (response_code = 200) { print "website alive" } else if (response_code = 204) { print "not found"; } ...

Leveraging colons in the process of object destructuring

I'm still trying to wrap my head around all the wonders of ES6. Ran across this snippet in an online article and I'm puzzled by how PrivateRoute is deconstructing the input props. What exactly is the purpose of component: Component here? const P ...

Utilizing MeteorJS Collection and Angular 2 for Efficient Data Visualization

I'm currently working on integrating the Rxjs Observable with the .zone() method to populate data in my Angular component from a MongoDB collection in MeteorJS. However, I've encountered an error stating 'Cannot read property 'title&apo ...

What is the best approach to integrate express.js with truffle contracts?

While following a tutorial on Youtube about creating a decentralized voting app on truffle, I encountered a situation where I wanted to include a login and sign up feature into the system. Since lite-server couldn't send Mysql queries like express.js ...

A plug-in for TinyMCE that allows users to adjust column widths within a table

We utilize TinyMCE in our content management system (CMS), and our users have expressed interest in being able to adjust the width of a column within a table. While HTML technically does not recognize columns, the Moodle editor HTMLAREA includes a plugin t ...

Can a VS Code theme extension be designed using JavaScript or TypeScript rather than JSON?

Currently working on a VS Code theme extension, I am interested in exploring the possibility of using JavaScript or TypeScript files instead of a JSON file. The idea of having all the theme information crammed into one massive JSON file feels disorganize ...

I am currently working on developing an HTML and JavaScript audio player that can play audio at specific scheduled times

Looking to create a custom HTML/JavaScript audio player that adjusts playback based on the time of day. For instance, if it's 1:00 pm, the file will start playing from 0:00 minutes; and if it's 1:01 pm, the file will begin playing from 1:00 minut ...

When a node using express encounters :id, it is directed to a specific location

Currently, I am in the process of creating a small API collection to familiarize myself with nodejs using express. In my project, I have included the line app.use("/v1/phrases", phraseRouter); Within the router file, the code looks like this: co ...

Guide on utilizing getelementsbytagname for retrieving LI values

As I attempt to locate a specific product on amazon.com, my goal is to extract the ASIN for each item. This particular code snippet runs through various search options and retrieves the price of each product from Amazon one by one. However, in addition to ...

Ways to leverage the power of Reactivity APIs in Vue.js

In my Vue application, I am trying to create a Drop Down Menu by using a variable called "showDropDown". The idea is to use a v-if directive to check if the value of showDropDown is true, and then display the menu accordingly. Additionally, I want to imp ...

Issue occurs where website fails to load homepage styling upon redirecting from the logout button

I currently have the following files set up on my website: index.php (contains a login form) login.php (holds the login script) home.php (main site) logout.php (simple destroy and redirect to index.php) The issue I am facing is that when I click the butto ...

Unable to add ngRoute dependency in Angular

I'm facing an issue while trying to set up a basic Angular route in my current project, encountering the error: Uncaught Error: [$injector:modulerr] I have ensured that I have injected ngRoute as a dependency in my module and included the angular-rou ...

Tips for concatenating elements to a previous state array when using an arrow function within the setState method?

When I drag and drop images to React-Dropzone library, I want to append them to the previous file state. const [files, setFiles] = useState([]) ... const { getRootProps, getInputProps, isFocused, isDragAccept, is ...

Determine the height of an element within an ng-repeat directive once the data has been fetched from an

After sending an ajax request to fetch a list of products, I use angular's ng-repeat to render them. I am attempting to retrieve the height of a div element that contains one product in the list. However, the console always displays "0" as the result ...

Refreshing a sibling component because of data changes in another sibling component within Next JS

I have a Next JS application where I am utilizing the Layout feature within the _app.tsx component. The layout includes a sidebar that is populated from an API call using a GET request. In addition, there is another API call (update request) triggered on ...

Guide on submitting a form in ReactJS with Material UI Dialog

I utilized the Material UI Dialog to create a form list. In the official example: <Dialog title="Dialog With Custom Width" actions={actions} modal={true} open={this.state.open} > This dialog ...

NodeJS - Deleting a variable in a text file (Replacing with empty space and eliminating the empty line)

I have a script that stores one-time use tokens in a text file. When the token is submitted via POST, the script checks if it exists in the file and I want to remove it afterwards. Currently, I am replacing the token with a blank line as shown in the cod ...

Having issues with retrieving data using findOne or findById in Express and Node JS, receiving undefined values

Currently, I am working on a microservice dedicated to sending random OTP codes via email. Below is the code for my findbyattr endpoint: router.get('/findbyattr/:email', async (request, response) =>{ try { let requestEmail = reque ...