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

Initialize element value from a Data Source query #105

Closed
rantinray opened this issue Oct 20, 2022 · 8 comments · Fixed by #107
Closed

Initialize element value from a Data Source query #105

rantinray opened this issue Oct 20, 2022 · 8 comments · Fixed by #107
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@rantinray
Copy link

rantinray commented Oct 20, 2022

I am trying to initialize a "Select with Custom options" element with Custom Code in the Initial Request. The initial request is '-' and the URL is blank as I am just trying to use data from a Prometheus query. I see that I have the values I want in the data element and I am able to assign them to the element.value fields. But this does not seem to affect the "initial" value which is used to detect changes in the elements and is shown as the "Old Value" in the confirmation table. Is there a way to set the initial value from Custom Code without an Initial Request query

@mikhail-vl mikhail-vl self-assigned this Oct 20, 2022
@mikhail-vl mikhail-vl added the enhancement New feature or request label Oct 20, 2022
@mikhail-vl mikhail-vl added this to the Version 2.6.0 milestone Oct 20, 2022
@mikhail-vl
Copy link
Member

mikhail-vl commented Oct 20, 2022

@rantinray Thank you for opening the feature request. I got the same issue recently, when tried to use Custom Code for the initial Request.

I will expose setInitial and you can set the initial hash of data like in the initialRequest.

@rantinray
Copy link
Author

@mikhail-vl Thank you for your response. Could you possibly provide an example usage when you have it implemented? I will watch for a new release!

@mikhail-vl
Copy link
Member

@rantinray I will, I hope to including it in the upcoming release this week.

@mikhail-vl
Copy link
Member

@rantinray PR merged and will be a part of the today's release:

To support Highlight changed values and Require Confirmation the Custom Code should use setInitial({}) function to update initial values:

  setInitial({value: 99, name: 'Test'})

@rantinray
Copy link
Author

rantinray commented Oct 24, 2022

@mikhail-vl I have installed the new v2.6.0 plugin to try to use the new 'setInitial()' function, but I am not able to get it to work. What value should I use for the 'name' property? I have been using the 'element.id' of the form element I want to initialize. Is this correct?

Thanks,
-Ray

@mikhail-vl
Copy link
Member

@rantinray To highlight and Require Confirmation, the panel verifies the value for each element with initial values set as a hash of element.id and values.

I agree. Maybe the example is misleading with name and value.
Here is the better version:

  setInitial({'id1':'value1', 'id2':'value2'})

Is it clear?

@rantinray
Copy link
Author

rantinray commented Oct 25, 2022

@mikhail-vl Yes, that is much clearer for me. I should have let you know that I eventually worked it out toward the end of my day. I am pretty new to javascript so between looking at your code and trial and error I worked it out. Thanks!

I have another possible enhancement request. Would it be possible to add a function called something like "updatedValues()" that returns a container of the update values in the form {'id1':'newValue1', 'id2':'newValue2', ...}. This would basically match the table you build for the confirmation dialog. This would be helpful to me when building the "Update Request". I currently have to send all form elements in the update when only a select few have changed. I don't believe there is any other way for me to determine what has changes in the form. Let me know if I should make this a "new" issue, or if it is out of scope. I can provide example screen shots of what I am doing if that helps.

Thanks again for your quick responses and very useful plugin!

-Ray

@mikhail-vl
Copy link
Member

@rantinray That's a totally valid request. Please open a new issue to track it and we will work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

2 participants