doumu8911 2019-08-14 07:14
浏览 517

未捕获的DOMException:无法在'Element'上执行'setAttribute':'1'不是Laravel刀片模板中的有效属性名称

I have a problem in my code, it is functional and but it bugs me with the console error I am getting from chrome.

My blade template code is:

<select name="business_unit_id" class="form-control">
 @foreach (App\Models\BusinessUnit::all() as $data)
  <option value="{{ $data->id }}"
   {{ old('business_unit_id', $cost_centers->business_unit_id ?? null)
    != $data->id ?: 'selected' }}>
    {{ $data->code.' - '.$data->descr }}
  </option>
 @endforeach
</select>

The console error are:

app.js:41637 Uncaught DOMException: Failed to execute 'setAttribute' on 'Element': '1' is not a valid attribute name.
    at baseSetAttr (http://ksakuws1137/js/app.js:43932:8)
    at setAttr (http://ksakuws1137/js/app.js:43907:5)
    at Array.updateAttrs (http://ksakuws1137/js/app.js:43862:7)
    at invokeCreateHooks (http://ksakuws1137/js/app.js:43218:22)
    at createElm (http://ksakuws1137/js/app.js:43105:11)
    at createChildren (http://ksakuws1137/js/app.js:43202:9)
    at createElm (http://ksakuws1137/js/app.js:43103:9)
    at createChildren (http://ksakuws1137/js/app.js:43202:9)
    at createElm (http://ksakuws1137/js/app.js:43103:9)
    at createChildren (http://ksakuws1137/js/app.js:43202:9)

The culprit is below, but that is needed to in order for the program to behave correctly.

{{ old('business_unit_id', $cost_centers->business_unit_id ?? null)
    != $data->id ?: 'selected' }}>

Anyone encounter the same issue and have a resolution? Thanks.

  • 写回答

1条回答 默认 最新

  • dsbfbz75185 2019-08-15 10:59
    关注

    I found the solution by changing the code in blade template from:

    {{ old('business_unit_id', $cost_centers->business_unit_id ?? null)
        != $data->id ?: 'selected' }}>
    

    To:

    {{ old('business_unit_id', $cost_centers->business_unit_id ?? null)
                                    != $data->id ? '' : 'selected' }}
    

    The culprit then is the "?:", maybe not compliant with HTML5?

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大