Why doesn’t form nested in p validate as XHTML

Look at the error messages that you get when you try that with http://validator.w3.org Apart from a warning that you haven’t specified a character encoding (and that it’s therefore assuming UTF-8), the main error is that a <p> isn’t allowed to contain non-inline content. You can either remove the <p> and </p> completely, or, move … Read more

How to send hidden data

try a hidden input: <input type=”hidden” value=”foo” name=”user_id” /> The user can’t see it, but remember that such inputs can be spoofed and need to be validated on the server just like any other input.

How to use the request in a ModelForm in Django

No, the request is not passed to the ModelForm. You’ll need to do something like this in your view: form = BookSubmitForm() form.fields[‘book’].queryset = Book.objects.filter(owner=request.user) # pass form to template, etc As you said, it’s often cleaner to encapsulate this in the Form object, particularly if you have several fields that will need filtered querysets. … Read more

Dynamic nested reactive form: ExpressionChangedAfterItHasBeenCheckedError

To understand the problem you need to read Everything you need to know about the ExpressionChangedAfterItHasBeenCheckedError error article. For your particular case the problem is that you’re creating a form in the AppComponent and use a {{myForm.valid}} interpolation in the DOM. It means that Angular will run create and run updateRenderer function for the AppComponent … Read more

How can I format the value shown in a Rails edit field?

The best I have come up with so far is something like this: <%= f.text_field :my_attribute, :value => number_with_precision(f.object.my_attribute) %> Or my_attribute could return the formatted value, like this: def my_attribute ApplicationController.helpers.number_with_precision(read_attribute(:my_attribute)) end But you still have to use :value <%= f.text_field :my_attribute, :value => f.object.my_attribute %> This seems like a lot of work.