Django - Localize widget attribute - django

I have a placeholder numeric value in a form field to serve as an example. That value is being passed as a widget attribute. Is there any way to have that value localized?

I have found django.utils.formats.number_format to work.

Related

Why does NullBooleanField in form give a dropdown when rendered in template?

When I change the form field to CharField, there is no dropdown in the template, BooleanField does not have one either. Why does NullBooleanField get a dropdown(in forms)? What if I dont want a drop down? Is this in built in generic view?
Due to the HTML specification of the checkboxes they only send value when checked. Quote from the HTML 4 spec:
When a form is submitted, only "on" checkbox controls can become successful.
You have no way to figure whether a missing values means it is just missing or is false.
NullBooleanField allows you to make that difference but it can not use a checkbox because of the HTML specifications so it has to fall back to a dropdown in order to offer a choice between false value and no value.

In Django what is the method of a `TextField` / `Field` object that returns its content?

In Django when needing to display the content of an object of type django.db.models.fields.TextField in a template, if this object is denoted as textfield, we can display it with the simple {{ textfield }} command.
However, while exploring the code of django.db.models.fields.TextField, I did not find any method returning the content of the TextField. Indeed, while checking django.db.models.fields.TextField and its super class django.db.models.fields.Field I did not find any method that do the job.
Thus, is there such a method returning the content of a TextField or even a Field, else what is the machinery used here to return it ?
That's not how Django fields work. Fields are attributes of the class, not the instance, and are used for loading and saving values from the database; the attribute on the instance is just the plain value.

How to pass parameters to Forms in Sitecore WFFM

Is there a way to pass custom values to a web form in WFFM?
There is a field named "Parameters" under the section "MVC Specific Settings" on "Form" template, setting this field by some values in the content editor and publishing, does not get transfer or populate to the Sitecore.Forms.Mvc.ViewModels.FormViewModel.
For Example:
You can try to get Parameters field value manually by getting rendering datasource item and then parsing Parameters field.

How to get the Value from a input field in QWebView

In Qt I have a QWebView on the screen the site in the web view has an input field,
I want to get the value attribute from the input field and store it in a QString
Basically what I'm asking is how can I store the value of a input field in a QString
From your QWebView get the QWebFrame (e.g ui->webView()->page()->currentFrame()->toHtml();) and then used QwebFrame::findAllElements or QWebFrame::findFirstElement. This will give you a QWebElement and you can use the attribute method to get the value attribute.
You should use evaluateJavaScript("this.value") for dynamic get calues from attributes:
http://www.qtforum.org/article/34091/solved-get-html-dom-dynamic-value-via-qtwebview.html#post109395

In Django, how to validate a (multiple) cholice field when the choices are added by Javascript?

I have a ChoiceField where the choices are not known at the time the HTML is rendered; they are defined dynamically by the user and added to the form through Javascript, but the validation naturally fails since the selected option is not in the choices attribute (which is just an empty list). I have tried setting the field to a CharField, but then the validator just gets a string value that needs to be converted into a list before it van be used. Ah, and I'd like to avoid subclassing the field class as it's just for one occasion.
I hope this is clear. Any ideas?
Don't subclass the field class but override the clean_<yourfield> method in your Form class. See the docs here.