forked from eagerworks/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from eagerworks/multiple_destinations
added multiple destinations
- Loading branch information
Showing
7 changed files
with
125 additions
and
47 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
// Connects to data-controller="destinations" | ||
export default class extends Controller { | ||
static targets = ['template', 'form', 'errorRemove'] | ||
static classes = ['paddingWeb', 'paddingMobile', 'hide'] | ||
|
||
|
||
add() { | ||
const newDestination = this.templateTarget.content.cloneNode(true) | ||
const inputs = newDestination.querySelectorAll('input') | ||
const id = this.formTarget.childElementCount | ||
inputs.forEach(input => { | ||
input.setAttribute('name', input.getAttribute('name').replace('[template]', `[destinations_attributes][${id}]`)) | ||
input.setAttribute('id', input.getAttribute('id').replace('[template]', `destinations_attributes_${id}`)) | ||
input.value = '' | ||
}) | ||
newDestination.querySelector('div').classList.add(this.paddingWebClass, this.paddingMobileClass) | ||
this.formTarget.appendChild(newDestination) | ||
this.errorRemoveTarget.classList.add(this.hideClass) | ||
} | ||
|
||
remove() { | ||
if (this.formTarget.childElementCount > 1) { | ||
this.formTarget.removeChild(this.formTarget.lastElementChild) | ||
this.errorRemoveTarget.classList.add(this.hideClass) | ||
} else { | ||
this.errorRemoveTarget.classList.remove(this.hideClass) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<div class="d-flex flex-column flex-lg-row column-gap-2 column-gap-lg-4" > | ||
<div class=""> | ||
<div class="mb-5 mb-sm-6 mb-lg-2"> | ||
<%= destination_form.text_field :receiver, placeholder: 'Nombre y apellido', class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-sm-5 fs-lg-1 pe-lg-2' %> | ||
<% destination_form.object.errors[:receiver].each do |message| %> | ||
<p class= "text-danger mb-0 fs-lg-1"><%= message %></p> | ||
<% end %> | ||
</div> | ||
<div class="mb-5 mb-sm-6 mb-lg-2"> | ||
<%= destination_form.label :day, 'Fecha de entrega', class:'text-role-grey fs-sm-5 fs-lg-3 d-lg-none' %> | ||
<%= destination_form.date_field :day, min: Date.today, class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-sm-5 fs-lg-1' %> | ||
<% destination_form.object.errors[:day].each do |message| %> | ||
<p class= "text-danger mb-0 fs-lg-1"><%= message %></p> | ||
<% end %> | ||
</div> | ||
<div class="mb-5 mb-sm-6 mb-lg-2"> | ||
<%= destination_form.text_field :address, placeholder: 'Dirección de entrega', class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-sm-5 fs-lg-1' %> | ||
<% destination_form.object.errors[:address].each do |message| %> | ||
<p class= "text-danger mb-0 fs-lg-1"><%= message %></p> | ||
<% end %> | ||
</div> | ||
</div> | ||
<div class=""> | ||
<div class="mb-5 mb-sm-6 mb-lg-2 "> | ||
<%= destination_form.text_field :number, placeholder: 'Número de contacto', class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-sm-5 fs-lg-1' %> | ||
<% destination_form.object.errors[:number].each do |message| %> | ||
<p class= "text-danger mb-0 fs-lg-1"><%= message %></p> | ||
<% end %> | ||
</div> | ||
<div class="mb-5 mb-sm-6 mb-lg-2"> | ||
<%= destination_form.text_field :schedules, placeholder: 'Horarios de entrega', class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-sm-5 fs-lg-1 pe-lg-2' %> | ||
<% destination_form.object.errors[:schedules].each do |message| %> | ||
<p class= "text-danger mb-0 fs-lg-1"><%= message %></p> | ||
<% end %> | ||
</div> | ||
<div class="mb-3"> | ||
<%= destination_form.text_field :cost, placeholder: 'Costo de envío', class: 'border-0 border-bottom-solid outline-none text-role-grey bg-transparent grey-placeholder w-100 fs-sm-5 fs-lg-1' %> | ||
<% destination_form.object.errors[:cost].each do |message| %> | ||
<p class= "text-danger mb-0 fs-lg-1"><%= message %></p> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters