I've got a dashboard that is POSTing stuff to a kv store. It currently clears the input forms once I hit submit, but the actual values seem to still be held in the tokens. For instance, I can hit submit five times in a row, even though the input forms have been cleared, but it will post the same values five times in a row instead one set of values and four blanks.
So yeah, how do I clear these token values?
Here is my html:
var submit = new SubmitButton({
id: 'submit',
el: $('#search_btn'),
text: 'Add to kv store'
}, {tokens: true}).render();
submit.on("submit", function() {
submitTokens();
// Below this point is from custom dashboard tutorial
// When the Submit button is clicked, get all the form fields by accessing token values from their Label field
var tokens = mvc.Components.get("default");
var form_ticket = tokens.get("form.ticket");
var form_type = tokens.get("form.type");
var form_value = tokens.get("form.value");
// Create a dictionary to store the field names and values
var record = {
"ticket": form_ticket,
"type": form_type,
"value": form_value
};
// Use the request method to send a REST POST request
// to the storage/collections/data/{collection}/ endpoint
service.request(
"storage/collections/data/mykvstore/",
"POST",
null,
null,
JSON.stringify(record),
{"Content-Type": "application/json"},
null)
.done(function() {
// Run the search again to update the table
search1.startSearch();
// Clear the form fields
$("#formaddtokvstore input[type=text]").val("");
});
});
To me it looks like it should be re .getting the variables each time which should be blank, but this is not what is happening. Should I just set my variables to empty at the end?
Don't know why I forgot this is js. I just reset the tokens at the bottom of the code like this:
tokens.set("for.ticket", "");
tokens.set("form.type", "");
tokens.set("form.value", "");
Don't know why I forgot this is js. I just reset the tokens at the bottom of the code like this:
tokens.set("for.ticket", "");
tokens.set("form.type", "");
tokens.set("form.value", "");
@thisissplunk,
I tried the same approach but it is not working for me. Can you please post the whole code ?