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

Extending the functionality of Intercooler to other controls #343

Open
camerontbelt opened this issue Sep 26, 2023 · 0 comments
Open

Extending the functionality of Intercooler to other controls #343

camerontbelt opened this issue Sep 26, 2023 · 0 comments

Comments

@camerontbelt
Copy link

I legitimately have no idea if this is the right place to do this or if this is even the right project but I'll post here to see if anyone can correct me.

My basic idea is can we extend this to add some smarts to other controls? I think to explain what I mean by that I need to show an example from some code I wrote at my job that is currently in production right now (please dont be too harsh).

<select id="States"></select>
.
.
.
<script>
   function LoadStates() {
       var url = `{MY ODATA API}`;
       fetch(url)
           .then(res => res.json())
           .then(data => {
               LoadSelectOptions(States, data.value, 'Name', 'ApiState');
           })
           .then(_ => {

               if (State.value === '') State.value = 42;
               SelectOptionByValue(States, State.value);
           });
   }
</script>

This is something that shows up quite often in my day to day, I have some control that I need to populate with some data so I write this little function on the page to load the list of states into my select control from an odata api endpoint. In this case it is also selecting a default state if another control is empty, in this case an input that was also populated by a similar JS function.

Im wondering if something like the following could be done to give some smarts to the HTML control so that boilerplate such as this would no longer be necessary.

EXAMPLE

<input id="State"/>

<select class="pinnergy-select" 
        id="States"
        ic-trigger="onload"
        ic-get-from="{MY ODATA API}"
        ic-select-value="ApiState"
        ic-select-text="Name"
        ic-select-default-value="42"
        ic-select-value-from="#State">
</select>

As you can see just adding some extra tags could eliminate most or all of the boilerplate javascript that a dev might encounter in their day to day. Maybe it already works this way and I just haven't read the manual closely enough to find this functionality but its something I would love to have to reduce the boilerplate in life.

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

1 participant