【问题标题】:laravel how to use star rating plugin on a form text inputlaravel 如何在表单文本输入上使用星级插件
【发布时间】:2017-01-22 15:40:54
【问题描述】:

我的项目是存储对产品的评论。我在这里使用 Laravel 框架。评论有一个用于对产品进行评级的字段。我正在使用 jquery 'starrr' 插件进行评分。

表格:

{!! Form::open(['url'=>'/admin/reviews', 'role' => 'form', 'class' => 'form-horizontal']) !!}
<div class="form-group">
{!! Form::label('title', "Title:", ['class'=>'control-label col-md-2']) !!}
<div class="col-md-8">
{!! Form::text('title', null, ['class'=>'form-control'])!!}
</div>
</div>
<div class="form-group">
{!! Form::label('product_id', "Product:", ['class'=>'control-label col-md-2']) !!}
<div class="col-md-8">
{!! Form::select('product_id', $products, null, ['class'=>'form-control product_list'])!!}
</div>
</div>
<div class="form-group">
{!! Form::label('rating', "Rating:", ['class'=>'control-label col-md-2']) !!}
<div class="starrr"></div>
{!! Form::hidden('rating', null, ['class'=>'form-control']) !!} 
</div>
<div class="form-group">
<div class="col-md-3 col-md-offset-4">
{!! Form::button('<i class = "fa fa-plus-circle"></i> Add New Review', ['type' => 'submit', 'class'=>'btn btn-primary btn-lg']) !!}
</div>
</div>
{!! Form::close() !!}

控制器存储方法:

public function store(Request $request){
$rules = [
            'product_id' => 'required',
            'title' => 'required',
            'content' => 'required',
];
$this->validate($request, $rules);
create($request->all());
return redirect('admin/reviews')->withSuccess('Review is created');
}

我的问题是如何从星级评分中获取评分值,并将其放入请求对象中以存储在数据库中? 提前感谢您的帮助

【问题讨论】:

    标签: laravel blade


    【解决方案1】:
    $('.starrr').starrr({
      change: function(e, value){
        $('input[name="value"]').val(value)
      }
    })
    

    这会将输入设置为starrr 插件的值,无论何时更改。然后将输入的值发送到服务器

    【讨论】:

    • 感谢杰夫。尝试了你的建议,但没有成功。 rev_rating 是名称字段。 $('input[rev_rating="value"]').val(value) 不断返回默认值 3。
    猜你喜欢
    • 1970-01-01
    • 2013-11-10
    • 1970-01-01
    • 1970-01-01
    • 2019-06-21
    • 1970-01-01
    • 2021-09-30
    • 2021-05-01
    • 1970-01-01
    相关资源
    最近更新 更多