I'm trying to do an update on a database record (postgres) with a ui-form (Dashboard 2), but I can't pass the id to the ui-form.
I don't get the id in the ui-form output so I can make the query and pass the id to modify.
I'm trying to do an update on a database record (postgres) with a ui-form (Dashboard 2), but I can't pass the id to the ui-form.
I don't get the id in the ui-form output so I can make the query and pass the id to modify.
I'm afraid there is not enough information here to help you.
NOTE: post code as text using the </>
code format button
thanks for your response.
Query
SELECT * FROM alarma WHERE id_equipo=1 ORDER BY id DESC LIMIT 1;
function get id
var id
var getid
if (msg.payload[0].rst === false) {
id = msg.payload[0].id;
msg.getid = id
}
else {
msg.getid = 1
}
return msg;
in debug 172, I get the id correctly.
output of the ui_form in debug 2573 (I have one field):
{"payload":{"1":"Siniestro"},"_client":{"socketId":"ZnmH_q-WKYeZpjXGAAIj","socketIp":"192.168.106.12"},"topic":"","_msgid":"45b2881273b0394b"}
I don't get an output with the field data and the id in the ui-form output to then do the query that updates the record in the db.
The dashboard docs for ui-form state:
If you want to set defaults, or pre-fill values in your form, you can do so by passing a
msg.payload
value. This value should be an object, where each key represents thekey
of a form element, and the value represents the default value for that element.
However, I cannot tell you what you need to send to your form since you did not show the ui-form fields as requested:
I think possibly @Pepex7 does not want the id to appear on the form, he/she just wants to pass it through so that it is available after the form. Is that correct @Pepex7?
yes, to be able to update the correct record.
Ah, that makes sense.
That is a good use case. Not sure "hidden fields" are supported however, it can be simulated with a join node or context.
You could add a number field with the name id
to the ui-form
and use CSS to make it hidden. Then it will be sent in the payload when you click submit.
Note. you should probably give the field a better name than "1" so it is easier to populate vlia msg.payload
If you set the id in msg.topic
in the message passed to the form, and in the form config set Topic to msg.topic
then that should be present in the form output.
thank you..!!
I tried it like that but nothing happened because the output of the ui-form only sends the form.
Show us what you are feeding into the form and what comes out.
Also the form config please.
That's what comes out of the form
{"payload":{"1":"Siniestro"},"_client":{"socketId":"ZnmH_q-WKYeZpjXGAAIj","socketIp":"192.168.106.12"},"topic":"","_msgid":"45b2881273b0394b"}
Enter a msg.getid (with the correct id)
Show us what you are feeding in and the form config (screenshot will do).
I suggested:
You haven't done that.
You have not shown the rest of the Form tab in the form config, where you need to:
Can I only put one class on the entire form? Not on a single field?
Why would you need to?
Just use a suitably targeted css selector to single out the form(s) field(s) you wish to style
e.g.
/* adjust look of ui-form with class my-class-1 */
.my-class-1 [data-form='form-row-id'] {
display: none; /* hide the field named id */
}
/* adjust look of ui-form with class my-class-1 and my-class-2 */
div.my-class-1.my-class-2 {
background-color: blue; /* color the main div */
}
/* etc etc */