With a hidden element, you reference the ID to get the posted value, what is name for then? - html

With a hidden element, you reference the ID to get the posted value, what is name for then?
Just wondering, do I even have to add that attribute in the HTML?

With any form element, including hidden type ones, only the name of the element is used to name the posted value.
You have to add the name attribute.

If you have
hidden_field_tag 'token', 'VUBJKB23UIVI1UU1VOBVI#'
in your view, you'll access the value in your controller with
params[:token]
Is that what you're asking?

Related

dash input suggestions using 'list' doesn't work

I'm trying to get the browser to autocomplete searches based on values from a list.
here is the relavant part from the dbc.Input docs:
list (string; optional): Identifies a list of pre-defined options to suggest to the user. The value must be the id of a <datalist> element in the same document. The browser displays only options that are valid values for this input element. This attribute is ignored when the type attribute's value is hidden, checkbox, radio, file, or a button type.
here is my code:
but still, when I start typing there are just no suggestions:
what's wrong?
You are providing string instead of variable, this doesn't seem right?

SignatureValue without Id attribute

When I sign an XML document I get:
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="xmldsig-f62dafae-6983-4b97-9b52-3f24c6960c43">
....
<ds:SignatureValue Id="xmldsig-f62dafae-6983-4b97-9b52-3f24c6960c43-sigvalue">
VpJzFiW62NK2ytlUkAYF....
</ds:SignatureValue>
....
</ds:Signature>
Is it possible to get ds:SignatureValue without the Id attribute?
It isn't possible to control the presence/value of that (and other) IDs, since it's hard-coded on the signer class. These IDs may be needed by some qualifying properties, hence being added.

Putting HTML in a hidden form field in Django

I'm having a problem with a template: I'm trying to display a form for changing a value, in which the user enters the current value in a textarea and the old value is kept inside a hidden field for auditing purposes. This value is generally some HTML, and when I render the page this HTML in the hidden field seems to get partially rendered: the value attribute of my hidden field gets closed by the first quotation marks inside the entered HTML, and the rest of the HTML spews out onto my page. I've tried using the escape decorator but that hasn't changed anything.
Firstly, a better solution might be to keep the audit value in a separate model field defined with editable=False. You can still perform checks against the value in a form's clean method:
def clean(self):
cleaned_data = super(SomeForm, self).clean()
if instance.the_audit_field == cleaned_data['the_editable_field']:
...raise a validation error?
You can also modify the value of the audit field from within the model's save method.
Secondly, assuming you must do it the way you are now, let me address the non-escaped value in your template. I assume you're using something like the following:
<textarea value="{{ form.the_audit_field.value }}"></textarea>
You should instead use the following:
<textarea>{{ form.the_audit_field.value }}</textarea>
Note, the value goes inside the textarea, instead of in the value attribute of it.
An even better way to do it is to simply allow Django to render the field for you like the following:
{{ form.the_audit_field }}

Name field not set for form input fields

I have a form and it contains multiple input fields. What if i don't provide an id or name to each and every field. will that field be submitted with some default name or won't be submitted at all.
This is just a query. No code involved.
Thanks
Form controls without names cannot be successful controls and will not be submitted.
The value of a control without a name will not be included in the submitted form data.
See HTML 4:
A successful control is "valid" for submission. Every successful control has its control name paired with its current value as part of the submitted form data set. A successful control must be defined within a FORM element and must have a control name.
or HTML 5:
If any of the following conditions are met, then skip these substeps for this element … The field element is not an input element whose type attribute is in the Image Button state, and either the field element does not have a name attribute specified, or its name attribute's value is the empty string.
The id is irrelevant to the success of a control. Only the name matters there.
The id is still important to include as it is the best way to associate a <label> element with a control (and has other uses via JS and CSS).
The form will still get submitted but you won't be able to get the 'post' values when the form has been submitted.

Updating a form field with a link

I have access to form field in the administrative view.
Example
<label>Number:</label>
<input type="text" name="title" size="50"/><br/>
I do not have access to modify the html syntax, the only thing i can do is updating the form field with a value.
In the form field i want to update it with a number. I also want to have a link assigned to that number.
So when i click that number it directs us to the link.
Is there a way i can do that?
This method is tedious, but you could use the jQuery nth-selector to select the specific form element that you are dealing with.
http://api.jquery.com/nth-child-selector/
This method is risky, however, since you might add other form elements before it, altering the index of your target input element.
Afterwords, you could use the .val() jQuery method to change your input value.
Nonetheless, again, this method is not safe because the index of the form element could change. I would beg the powers of be to be able to add an ID or some identifying attribute to that form element.