Elixir ExAdmin, how to define boolean input as a checkbox? - checkbox

In ExAdmin, how can I make the input field of a boolean render as a checkbox.
By default (i.e. empty register_resource App.Reservation do end) it shows up as a checkbox, but I need to customize the form and can't get it to be a checkbox when defining it in the inputs list.
register_resource App.Reservation do
form reservation do
inputs do
input reservation, :is_booked
end
end
end
The documentation mentions check_boxes and radio for groups but not for single fields.
input reservation, :is_booked will create a text field.
input reservation, :is_booked, type: :boolean will create a text field that says true as a default value.
Would like to have it as a checkbox

The problem I had was that I forgotten to define the field type in model. Once I did that it worked!
schema "users" do
...
field :active, :boolean, default: false
...
end
in admin for user.ex
inputs do
...
input user, :active
...
end

Related

How do you validate a select box in React Final Form

I'm trying React Final Form. How can I validate the user has selected a value in a "select" box and that it is not longer the initial value. I'm using a Field like this, then just adding options by mapping an array.
<Field
flex="1 0 200px"
name="project-busOrgId"
component="select"
>
Your two options are field-level validation, where you specify a validate prop to <Field/> or record-level validation, where you validate all the form values at once and return an object of errors. Up to you.

AngularJS: invalid input is not styled as invalid until I click on the input field and click out of it

I am setting input field to invalid from javascript like this:
$scope.formName.fieldName.$setValidity("string", false);
This is working, but it affects the view only after clicking in a input field and then clicking out of it.
How can I change it in order to see the invalid field immediatelly?
You'll need to attach an ng-change="checker(model)" to your input field. Then just apply an ng-class to it to check for formName.fieldName.$error.string (since you put string as the error key) or you can also do formName.fieldName.$invalid && !formName.fieldName.$pristine
I've attached this codepen for you to play around with and see how to apply an invalid class on the field without having to lose focus on it.
Hope that helps!

angularjs typeahead with enter event

I want to display textbox with dropdown. when user enter text, it will call the function to access DB and returns list of users which match with entered text. that users list will be displayed in dropdown along with textbox like typeahead.
I am going to use angular typeahead for search users.
but my users list contains around 16000 data.
when i use typeahead, if I type a single character, it will call the async function,then all data will return filtered by that character.
So i would like to call that async function after user typed and press enter key.
Is there any other solution to achieve this?
or is there any other plugin for my requirement?
Thanks.
I have used typeahead-min-length attribute instead of enter functionality.

Getting Parsley 2 working with Bootstrap 4

By default, Parsley only handles updating a single element's class (usually the input field in which the invalid entry is). However, with Bootstrap 4 we must update both the form-group and the input field classes to render them with the validation icons. Otherwise, only the border colour is changed.
How can I use Parsley to correctly, completely style my input fields when validating user input in the client?
In order to correctly style Bootstrap 4 with Parsley, you must modify the classes of the div.form-group surrounding your input fields (assuming you want the validation icons, like I did).
According to the documentation you need to add .has-success or .has-danger to the div.form-group and then specify form-control-success and form-control-danger respectively to the input fields.
However, Parsley only supports updating the class on a single element by default. Fortunately, it supports event binding, so with a little function added to the end of your parsley.js file, we can handle updating the div.form-group styles when the user has fixed a validation error.
First configure Parsley:
errorClass: "form-control-danger",
successClass: "form-control-success"
These are the correct classes to apply to the input fields, which Parsley works on by default. Next, append the following to the parsley.(min).js file.
window.Parsley.on('field:validated', function(e) {
if (e.validationResult.constructor!==Array) {
this.$element.closest('.form-group').removeClass('has-danger').addClass('has-success');
} else {
this.$element.closest('.form-group').removeClass('has-success').addClass('has-danger');
}
});
The above will listen for when fields have been validated, and, hence update the relevant div.form-group according to the Bootstrap 4 documentation to ensure that the input field gets rendered appropriately.

how to add a empty string as default in the drop down where dropdown is a directive

In my AngularJS project, I am having a dropdown field as a directive and the values are coming from the backend.The user can also leave the field without selecting the dropdown(optional field) but the problem is, there is no empty field from the backend. So I need to add an empty field into the dropdown as default.
Since there is no option in the directive got struck in this issue.Googled a lot but didnt get any solutions yet.Kindly provide some suggestion.
Note:Client machine,cant post the code.
If there is no value set for the ng-model that the dropdown is bound to, Angular will provide a blank option by default that can be left in place (ignored) by the user and will result in your final value being whatever you set that ng-model to in the first place. If you need an actual empty string for the value, initialize it to that.
If you need to enable the user to select an empty value once they have already selected a value, you will need to add an empty value to the object that the dropdown is bound to. Add the empty value like this:
myPromise.then(function(data){
$scope.ddInfo = data;
$scope.ddInfo.unshift({id:'0000',text:'Not Applicable'});
});

Resources