Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Dynamically create objects #53

Open
MasterPuffin opened this issue Feb 18, 2025 · 4 comments
Open

Feature Request: Dynamically create objects #53

MasterPuffin opened this issue Feb 18, 2025 · 4 comments

Comments

@MasterPuffin
Copy link

Hi,
I would like to show an input field, if a select has a specific value. However I would like to not initialize Sprae with the required object but have Sprae detect the required object automatically.
I wrote a function as a proof of concept that achieves this, however my question would be, if that could be natively integrated in Sprae.

<div id="container">
    <select class="form-control" :value="object1">
        <option value="1">Test 1</option>
        <option value="2">Test 2</option>
        <option value="3">Test 3</option>
    </select>
    <input :if="object1 == 3" type="text" class="form-control">
</div>
const container = document.querySelector('#container')
const elements = Array.from(container.querySelectorAll('*')).filter((el) => {
    return el.hasAttribute(':value');
});

const objects = {}
elements.forEach((element) => {
    objects[element.getAttribute(':value')] = null;
});
const state = sprae(container, objects)
@dy
Copy link
Owner

dy commented Feb 19, 2025

Not sure I understand - your example works fine (just make sure input is closed, as <input />).
Can you show what would you like to have that doesn't work now?

@MasterPuffin
Copy link
Author

The code above works as intended, however my question was, if this behavior could be integrated in Sprae, so that my JS code wouldn't be needed anymore?

@dy
Copy link
Owner

dy commented Feb 19, 2025

You can init sprae on root and it should work, doesn't it?

@dy
Copy link
Owner

dy commented Feb 27, 2025

@MasterPuffin can you elaborate a bit, how would see it should work that it doesn't work now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants