I am trying to add the class "form-control" to a select tag like this am using rails, haml and simple form
= form.country_select "addr_country", class: 'form-control"
but I get this output:
<select id="order_addr_country" name="order[addr_country]">
<option value="form-control">class</option
...
Any ide why?
this way:
= form.country_select "model", "attribute", {class: 'form-control'}
don't know whether addr_country is a model or attribute
Related
How can I make a dependent dropdown country ,state,city country, state, and city in user ragistration registration using laravel Laravel 8 jetstream .. ?JetStream?
Assuming you are using the Livewire + Blade Stack, as per the official documentation:
Each of these templates will receive the entire authenticated user object so that you can add additional fields to these forms as necessary. Any additional inputs added to the forms will be included in the $input array that is passed to your UpdateUserProfileInformation action.
The above means that you will need some vanilla Laravel, HTML (or Blade partial) and a Livewire model tag.
Add any necessary migration to the users table.
Add in the given $fillable property to the User model:
//app/Models/User.php
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
...
'city', //Assuming new column name is city
...
];
Add in any input validation logic and the property it will be saved to on App\Actions\Fortify\UpdateUserProfileInformation action class.
//app/Actions/Fortify/UpdateUserProfileInformation.php
$user->forceFill([
...
'city' => $input['city'],
...
])->save();
Modify resources/views/profile/update-profile-information-form.blade.php to include the HTML or partial that renders the dropdown select box:
//resources/views/profile/update-profile-information-form.blade.php
//Assuming the column name is 'city'
//Assuming you are not using a Blade partial
<div class="col-span-6 sm:col-span-4">
<x-jet-label for="city" value="{{ __('City') }}" />
<select
name="city"
id="city"
class="block w-full mt-1"
wire:model.defer="state.city"
>
<optgroup label="Ontario">
<option value="toronto">Toronto</option>
<option value="markham">Markham</option>
</optgroup>
<optgroup label="Quebec">
<option value="montreal">Montreal</option>
<option value="qc">Quebec City</option>
</optgroup>
</select>
Please notice that Livewire should take care of any data bindings via the tag wire:model.defer="state.city".
I want to set a multipart attribute for a html.Dropdownlist. How to do this?
#Html.DropDownList("ProductTypesId",DropdownHelper.GetAllProductTypes("-1"), new { #class="selectpicker", multiple title = "Select One" })
But I have error for the multiple title attribute.
Update
The error is:
The name multiple doesn't exist in the current context.
"multiple title" is not an attribute in HTML. Attributes are space-separated.
What you have is a single-label attribute "multiple" and the second attribute "title="Select one"
HTML allows for single-label attributes to have their name as a value - this has the same effect and is how XHTML supports single-label attributes, like so:
new { #class="selectpicker", multiple="multiple" title="Select One" }
this will be rendered like this:
<select class="select picker" multiple="multiple" title="Select One">
Also, you can write in htmlAttributes object like that
#multiple="multiple"
What is the best way to create the following HTML using simple_form_for gem?
<label>
<input name="form-field-radio" type="radio" />
**<span class="lbl"> radio option 2</span>**
</label>
Note that by default when I create a radio buttons using the following statements, the above is not created. How can I add that tag in?
<%= f.input :state, :collection => Project::STATES, :as => :radio_buttons %>
I had a similar need (to embed a <span> within the <label>). It isn't the cleanest solution but it did work and I think with some tweaking it could get you the ability to have your input and span embedded within the label. The following modification results in:
<label>Name:
<span class="hint">this is a hint...</span>
</label>
I added the following as an initializer (using rails 4 and simple_form 3) to override the label_text method:
# initializers/simple_form_custom.rb
module SimpleForm
module Components
module Labels
def label_text
if hint
hint_text = %[<span class="hint">#{hint}</span>]
else
hint_text = ""
end
SimpleForm.label_text.call(raw_label_text, required_label_text, hint_text).strip.html_safe
end
end
end
end
Then in initializers/simple_form.rb I have:
config.label_text = lambda { |label, required, hint| "#{label}: #{required} #{hint}" }
I don't know how much code is needed in order for you to understand my problem so I'm starting with explaining what I want to do.
I have a form in my View where I create a new object.
In this form I want to use a dropdownlist and I've tried a lot with #Html.Dropdownlistfor() but realized I don't want to use that since I don't know how to use som Jquery UI-code on this and I don't know how to send a different value than what is shown in the dropdownlist.
Does any of you know how i just send the value selected in the dropdownlist to my controller?
DropDownListFor helper method esssentially render a SELECT element. So if you do not want to use the helper method, You may write the RAW HTML code
#model CreateUserVM
#using(Html.BeginForm())
{
<select name="SelectedCity" id="SelectedCity">
<option value='1'>Ann Arbor</option>
<option value='2'>Novi</option>
<option value='3'>Detroit</option>
</select>
}
Make sure your SELECT elements name property value is same as what you use in your Model, so that Model binding will work.
public class CreateUserVM
{
public int SelectedCity { set;get;}
//other properties
}
In view model:
puclic class ViewModel
{
int SelectId{get;set;}
}
In view
<select name="SelectId" id="SelectId">
<option value='1'>one</option>
<option value='2'>Two</option>
</select>
After post form ViewModel.SelectId will contain value of selected item in dropdown
When writing functional tests, how can I set the value of a select box if I only have the label of the option I want, but not the actual value?
I'm not sure I got exactly what you need, I suppose you have a form like this
<form action="..." method="post">
...
<select id="my_form_category" name="my_form[category]">
<option value="1">category1</option>
<option value="2">category2</option>
<option value="3">category3</option>
</select>
...
<button type="submit">Edit</button>
</form>
and you want to select category2. Even if you don't know the option value you can use the crawler to extract it
$client = static::createClient();
// go to form
$crawler = $client->request('GET', '...');
$value = $crawler->filter('#my_form_category option:contains("category2")')->attr('value');
$form = $crawler->selectButton('Edit')->form();
$form['my_form[category]']->select($value);
// ... set other values
$client->submit($form);