How to name the blank value in select?

It depends on how you are constructing your options for select. If you’re doing it like the code below, just pass a string into the :include blank. select(“post”, “person_id”, Person.all.collect {|p| [ p.name, p.id ] }, {:include_blank => ‘Some text here’}) If you’re setting the options with a options_for_select(), then you can do something like … Read more

why doesn’t hitting enter when a SELECT is focused submit the form?

It’s simply the nature of the control. The Enter key (or a mouse click) is what makes the selection. To submit the form when pressing Enter would result in a poor user experience, since the form would essentially be unusable. I would not recommend changing the behavior via JavaScript, simply because the default behavior is … Read more

Validation in HTML5. :invalid classe after submit

I used this approach for a project of mine, so the invalid fields would be highlighted only after submit: HTML: <form> <input type=”email” required placeholder=”Email Address”> <input type=”password” required placeholder=”Password”> <input type=”submit” value=”Sign in”> </form> CSS: input.required:invalid { color: red; } JS (jQuery): $(‘[type=”submit”]’).on(‘click’, function () { // this adds ‘required’ class to all the … Read more

Can I trigger a form submit from a controller?

You can add submit method to a FormController. I did so: <form ng-form-commit action=”https://stackoverflow.com/” name=”payForm” method=”post” target=”_top”> <input type=”hidden” name=”currency_code” value=”USD”> <button type=”button” ng-click=’save(payForm)’>buy</button> </form> .directive(“ngFormCommit”, [function(){ return { require:”form”, link: function($scope, $el, $attr, $form) { $form.commit = function() { $el[0].submit(); }; } }; }]) .controller(“AwesomeCtrl”, [“$scope”, function($scope){ $scope.save = function($form) { if ($form.$valid) { … Read more

Add class to Django label_tag() output

Technique 1 I take issue with another answer’s assertion that a filter would be “less elegant.” As you can see, it’s very elegant indeed. @register.filter(is_safe=True) def label_with_classes(value, arg): return value.label_tag(attrs={‘class’: arg}) Using this in a template is just as elegant: {{ form.my_field|label_with_classes:”class1 class2″}} Technique 2 Alternatively, one of the more interesting technique I’ve found is: … Read more

Angularjs how to upload multipart form data and a file?

First of all You don’t need any special changes in the structure. I mean: html input tags. <input accept=”image/*” name=”file” ng-value=”fileToUpload” value=”{{fileToUpload}}” file-model=”fileToUpload” set-file-data=”fileToUpload = value;” type=”file” id=”my_file” /> 1.2 create own directive, .directive(“fileModel”,function() { return { restrict: ‘EA’, scope: { setFileData: “&” }, link: function(scope, ele, attrs) { ele.on(‘change’, function() { scope.$apply(function() { var … Read more