add renderWithOutSubmitButton and disabled apis for OptionForm

This commit is contained in:
printempw 2016-12-31 15:11:49 +08:00
parent ee5fec149e
commit dcbeb35155
6 changed files with 40 additions and 11 deletions

View File

@ -26,6 +26,7 @@ class OptionForm
protected $renderWithOutTable = false;
protected $renderInputTagsOnly = false;
protected $renderWithOutSubmitButton = false;
/**
* Create a new option form instance.
@ -301,6 +302,13 @@ class OptionForm
return $this;
}
public function renderWithOutSubmitButton()
{
$this->renderWithOutSubmitButton = true;
return $this;
}
/**
* Get the string contents of the option form.
*
@ -312,6 +320,16 @@ class OptionForm
call_user_func($this->alwaysCallback, $this);
}
// attach submit button to the form
if (!$this->renderWithOutSubmitButton) {
$this->addButton([
'style' => 'primary',
'text' => trans('general.submit'),
'type' => 'submit',
'name' => 'submit'
]);
}
$this->assignValues();
return view('vendor.option-form.main')->with(array_merge(get_object_vars($this)))->render();
@ -338,6 +356,8 @@ class OptionFormItem
public $value = null;
public $disabled;
public $description;
public function __construct($id, $name = null)
@ -360,6 +380,13 @@ class OptionFormItem
return $this;
}
public function disabled($disabled = "disabled")
{
$this->disabled = "disabled=\"$disabled\"";
return $this;
}
public function description($description)
{
$this->description = $description;
@ -384,8 +411,9 @@ class OptionFormText extends OptionFormItem
public function render()
{
return view('vendor.option-form.text')->with([
'id' => $this->id,
'value' => $this->value
'id' => $this->id,
'value' => $this->value,
'disabled' => $this->disabled
]);
}
}
@ -406,7 +434,8 @@ class OptionFormCheckbox extends OptionFormItem
return view('vendor.option-form.checkbox')->with([
'id' => $this->id,
'value' => $this->value,
'label' => $this->label
'label' => $this->label,
'disabled' => $this->disabled
]);
}
}
@ -427,7 +456,8 @@ class OptionFormTextarea extends OptionFormItem
return view('vendor.option-form.textarea')->with([
'id' => $this->id,
'rows' => $this->rows,
'value' => $this->value
'value' => $this->value,
'disabled' => $this->disabled
]);
}
}
@ -448,7 +478,8 @@ class OptionFormSelect extends OptionFormItem
return view('vendor.option-form.select')->with([
'id' => $this->id,
'options' => $this->options,
'selected' => $this->value
'selected' => $this->value,
'disabled' => $this->disabled
]);
}
}

View File

@ -1,3 +1,3 @@
<label for="{{ $id }}">
<input {!! $value ? 'checked="true"' : '' !!} type="checkbox" id="{{ $id }}" name="{{ $id }}" value="true"> {{ $label }}
<input {!! $value ? 'checked="true"' : '' !!} type="checkbox" id="{{ $id }}" name="{{ $id }}" {{ $disabled or '' }} value="true"> {{ $label }}
</label>

View File

@ -32,8 +32,6 @@
</div><!-- /.box-body -->
<div class="box-footer">
<button type="submit" name="submit" class="btn btn-primary">{{ trans('general.submit') }}</button>
@foreach($buttons as $button)
{!! $button !!}
@endforeach

View File

@ -1,4 +1,4 @@
<select class="form-control" name="{{ $id }}">
<select class="form-control" name="{{ $id }}" {{ $disabled or '' }}>
@foreach ((array) $options as $option)
<option {!! $selected == $option['value'] ? 'selected="selected"' : '' !!} value="{{ $option['value'] }}">{{ $option['name'] }}</option>

View File

@ -1 +1 @@
<input type="text" class="form-control" name="{{ $id }}" value="{{ $value }}">
<input type="text" class="form-control" name="{{ $id }}" {{ $disabled or '' }} value="{{ $value }}">

View File

@ -1 +1 @@
<textarea class="form-control" rows="{{ $rows }}" name="{{ $id }}">{{ $value }}</textarea>
<textarea class="form-control" rows="{{ $rows }}" name="{{ $id }}" {{ $disabled or '' }}>{{ $value }}</textarea>