【发布时间】:2018-02-22 14:30:34
【问题描述】:
我有一个包含一些单选按钮的表单,在单选按钮下方,有一些输入字段
一个单选按钮是静态的,“创建新的注册类型”,单击时表单字段应重置,以便用户可以在字段中插入新值,以便他可以为会议存储新的注册类型。
其他单选按钮是动态的,对应于数据库中特定会议的注册类型。当检查这些单选按钮中的每一个时,我想在表单字段中显示该特定检查的注册类型的信息(名称,容量等),以便可以更新每个注册类型。
怀疑
你知道如何组织这个逻辑吗?我在这方面没有成功。页面需要刷新吗?或者注册类型可以一次全部加载,然后使用 jquery 在每个单选按钮选择上显示每个注册类型?还是没有?
编辑注册表单:
<form method="post" class="clearfix">
<div class="form-row">
<div class="form-group col col-lg-6">
<label for="registration_types">Registration Types</label>
@foreach($registrationType as $rtype)
<div class="form-check">
<input class="form-check-input" type="radio" name="radiobutton" id="{{$rtype->id}}" value="option1">
<label class="form-check-label" for="exampleRadios1">
{{$rtype->name}}
</label>
</div>
@endforeach
<div class="form-check">
<input class="form-check-input" type="radio" name="radiobutton" id="create_registration_type" checked value="option1">
<label class="form-check-label" for="exampleRadios1">
Create new registration type
</label>
</div>
</div>
</div>
<div class="form-group">
<label for="registration_type_name">Registration Type Name</label>
<input type="text" required class="form-control" value="{{ $rtype->nome }}" name="registration_type_name" id="registration_type_name">
</div>
<div class="form-group">
<label for="registration_type_capacity">Capacity</label>
<input type="number" min="1"
required class="form-control" value="{{ $rtype->capacity }}"
name="registration_type_capacity" id="registration_type_capacity">
</div>
<!-- more registration type info fields -->
</div>
<input type="submit" class="btn btn-primary" value="Store registration type"/>
<input type="submit" class="btn btn-primary" value="Update registration type"/>
</form>
RegistrationType 控制器:
class RegistrationTypeController extends Controller
{
public function edit($id)
{
$conference = Conference::find($id);
$registrationType = RegistrationType::where('conference_id', $id)->get();
return view('rtypes.edit')->with('conference', $conference)->with('registrationType', $registrationType);
}
public function update(Request $request, $id){
$this->validate($request, [
'registration_type_name' => 'required|string',
'registration_type_description' => '',
]);
$conference = Conference::find($id);
$regType = RegistrationType::find($conference->id);
$regType->name = $request->registration_type_name;
$regType->description = $request->registration_type_description;
...
$regType->save();
Session::flash('success','Registration type updated with success');
return redirect()->back();
}
}
注册类型模型
class RegistrationType extends Model
{
protected $fillable = [
'name', 'description', 'capacity', 'conference_id'
];
public function confenrence(){
return $this->belongsTo('App\Conference');
}
}
JS:
<script>
$('#create_registration_type').click(function(){
$('input[type="text"]').val('');
$('input[type="number"]').val('');
$('input[type="submit"]').val('Store');
});
</script>
【问题讨论】:
-
您是如何尝试问题的第二部分的?你有相关的代码吗?
-
在问题描述中添加控制器代码