Git Product home page Git Product logo

Comments (5)

cferdinandi avatar cferdinandi commented on May 29, 2024

I think that's a really good idea!

from reef.

cferdinandi avatar cferdinandi commented on May 29, 2024

@Roguelazer I was thinking about this more, and... I'm realizing the reason I didn't support functionality like that with these attributes to start with is that they can't really be modified by user interactions like selected, checked, etc. can be.

Can you tell me a bit more about the use case here?

from reef.

Roguelazer avatar Roguelazer commented on May 29, 2024

I think I was disabling fields while an HTTP request runs

from reef.

cferdinandi avatar cferdinandi commented on May 29, 2024

@Roguelazer I think this should work out-of-the-box...

return `<button ${data.disabled ? 'disabled' : ''}>Submit</button>`

That said, I'd actually recommend you NOT do this, as disabling buttons that have focus shifts focus to the document and creates confusing accessibility issues for screen reader users.

I suggest adding a class that changes the color/opacity of elements without disabling them, and simply ignoring additional submits until the HTTP request is completed, like this...

function template () {
    return `
        <form>
            <!-- form field stuff -->
            <button ${data.submitting ? 'class="disabled"' : ''}>Submit</button>
            <div role="status">${data.submitting ? 'Submitting...' : ''}</div>
        </form>`;
}

let data = store({
    submitting: false
});

document.addEventListener('submit', function (event) {

    // Don't let the form reload the page
    event.preventDefault();

   // If the form is already being submitted, ignore request
   if (data.submitting) return;
   
   // Add data-submitting attribute
   data.submitting = true;
   
   // Do your HTTP stuff...
   
   // Then, reenable the form
   data.submitting = false;

});
.disabled {
    opacity: 0.7;
}

from reef.

cferdinandi avatar cferdinandi commented on May 29, 2024

Sorry, I'm closing this as unnecessary given that there's an alternate approach. The boolean hack for checked etc. exists primarily as a quick for how user-defined variables work in the DOM.

from reef.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.