Comments (5)
I think that's a really good idea!
from reef.
@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.
I think I was disabling fields while an HTTP request runs
from reef.
@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.
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)
- License? HOT 2
- Add support for on* events that does so safely HOT 2
- 12.3 has broken my app HOT 2
- jsdoc issue HOT 2
- Listeners remove html attributes HOT 4
- Event functions with parameters HOT 3
- Rename store(), setters() to align with industry norms (breaking change) HOT 1
- Add a way to ignore certain elements when diffing the DOM HOT 1
- How to read a signal's data built via a store? HOT 5
- Add getter methods to store() object
- tbody element not supported as a component root HOT 3
- Add option to keep attributes on nodes with [reef-keep] HOT 9
- onclick attribute removed by reef HOT 3
- Reef types HOT 2
- to do demo bug
- Component composition HOT 2
- Second event handler not correctly registered HOT 4
- 13.0.3 has broken attributes on html HOT 2
- Is the store function doesn't work with component? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reef.