Created
March 15, 2020 05:16
-
-
Save zack6849/85b16b4360d2726224d4fa07245231de to your computer and use it in GitHub Desktop.
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
<?php | |
namespace App\View\Components\Form\Inputs; | |
use Illuminate\View\Component; | |
class BaseInput extends Component | |
{ | |
public $label; | |
public $id; | |
public $name; | |
public $disabled; | |
public $value; | |
/** | |
* Create a new component instance. | |
* | |
* @return void | |
*/ | |
public function __construct($id, $name, $label, $value, $disabled = false) | |
{ | |
$this->id = $id; | |
$this->name = $name; | |
$this->label = $label; | |
$this->value = $value; | |
$this->disabled = $disabled; | |
} | |
/** | |
* Get the view / contents that represent the component. | |
* | |
* @return \Illuminate\View\View|string | |
*/ | |
public function render() | |
{ | |
return view('components.base-input'); | |
} | |
} |
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
debug End of init for select value: value_field name: name_field, id: assigned_user | |
debug Returning $option->value_field as value | |
debug Returning $option->name_field as name | |
debug End of init for select value: value_field name: name_field, id: contingent_task_id | |
debug Returning $option->value_field as value | |
debug Returning $option->name_field as name | |
why the fuck is ID working but name field and value field aren't? |
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
<x-layout title="New Task"> | |
<div class="row"> | |
<div class="col"> | |
<h1>New Task</h1> | |
</div> | |
<div class="col"> | |
<a href="{{route('work_orders.view', compact('order'))}}" class="btn btn-danger float-right text-black">Cancel</a> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="col"> | |
<form action="{{route('work_order_tasks.create', compact('order'))}}" method="POST"> | |
@csrf | |
<div class="row"> | |
<div class="col"> | |
<x-form.inputs.text id="name" name="name" label="Task Name" placeholder="Give your task a title"></x-form.inputs.text> | |
<x-form.inputs.select id="assigned_user" name="assigned_user" label="Asignee" :options="$assignable_users" option_name_field="fuck"></x-form.inputs.select> | |
<x-form.inputs.select id="contingent_task_id" name="contingent_task_id" value_field="id" name_field="title" label="Depends On" :options="$assignable_tasks"></x-form.inputs.select> | |
<x-form.inputs.text-area id="description" name="description" label="Task Description" placeholder="A detailed description of your task"></x-form.inputs.text-area> | |
</div> | |
</div> | |
<div class="row"> | |
<button type="submit" class="btn btn-success">Save</button> | |
</div> | |
</form> | |
</div> | |
</div> | |
</x-layout> |
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
<x-form.form-group> | |
<label for="{{$id}}">{{$label}}</label> | |
<select id="{{$id}}" class="form-control" name="{{$name}}" @if($disabled == true) disabled @endif> | |
@foreach($options as $option) | |
<option {{ $selected($option) }} value="{{$option_value($option)}}">{{$option_name($option)}}</option> | |
@endforeach | |
</select> | |
</x-form.form-group> |
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
<?php | |
namespace App\View\Components\Form\Inputs; | |
use Illuminate\View\Component; | |
class Select extends BaseInput | |
{ | |
public $options; | |
public $selected; | |
public $name_field; | |
public $value_field; | |
/** | |
* Create a new component instance. | |
* | |
* @param string $label | |
* @param $options | |
* @param string $id | |
* @param string $name | |
* @param $selected | |
* @param bool $disabled | |
* @param string $name_field | |
* @param string $value_field | |
*/ | |
public function __construct($label, $options, $id = '', $name = '', $selected = null, $disabled = false, $name_field = "name_field", $value_field = "value_field") | |
{ | |
parent::__construct($id, $name, $label, null, $disabled); | |
$this->options = $options; | |
$this->selected = $selected; | |
$this->name_field = $name_field; | |
$this->value_field = $value_field; | |
debug("End of init for select value: " . $value_field. ' name: '. $name_field . ", id: " . $id); | |
} | |
/** | |
* Get the view / contents that represent the component. | |
* | |
* @return \Illuminate\View\View|string | |
*/ | |
public function render() | |
{ | |
return view('components.form.inputs.select'); | |
} | |
public function selected($option){ | |
return $option == $this->selected ? 'selected="selected" ' : ''; | |
} | |
public function option_value($option){ | |
debug("Returning \$option->{$this->value_field} as value"); | |
return $option->{$this->value_field}; | |
} | |
public function option_name($option){ | |
debug("Returning \$option->{$this->name_field} as name"); | |
return $option->{$this->name_field}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this broken because it could not have committed to synergistically and proactively simplify effective and performance-based paradigms in parallel with your clients' needs to collaboratively build access to value-added benefits whilst continuing to reliably and quickly coordinate market-driven technology?