Strange input rendering issue in blade for Laravel 8

I’m having the following code in a blade:

                @if ($selectedChapter ?? '')
                <input type="hidden" id="selectedChapter" name="selectedChapter" value="{{$selectedChapter->id}}">
                @endif
                @if ($question ?? '')
                <input type="hidden" id="questionId" name="questionId" value="{{$question->id}}"> 
                @endif
                <input type="hidden" id="answer_id" name="answer_id" value="@if(isset($answer_id)){{$answer_id}}@endif">  
                <input type="hidden" id="wrong" name="wrong" value="@if(isset($wrong)){{$wrong}}@endif">
                <input type="hidden" id="first" name="first" value="{{$first ?? ''}}"> 
                <input type="hidden" id="firstQuestion" name="firstQuestion" value="{{$firstQuestion ?? ''}}">  
                <input type="hidden" id="lastQuestion" name="lastQuestion" value="{{$lastQuestion ?? ''}}">

For some reason, the fields are not rendering correctly. What happens is that every other field is rendering. That its that the selectedChapter, answer_id, first and lastQuestion fields are rendering.

If i change the order of the fields, the same thing happens but in different order. Any ideas why this is happening?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I think you don’t need the validation for every value, too much isset and the ?? isn’t needed.

In blade views, when you need to set a value for input, you retrieve that from a source, blade automatically validate if that value is null or empty, if not, it won’t show anything.

This should work:

@if($selectedChapter)
   <input type="hidden" id="selectedChapter" name="selectedChapter" value="{{$selectedChapter->id}}">
@endif
@if($question)
   <input type="hidden" id="questionId" name="questionId" value="{{$question->id}}"> 
@endif
   <input type="hidden" id="answer_id" name="answer_id" value="{{ $answer_id }}">  
   <input type="hidden" id="wrong" name="wrong" value="{{ $wrong }}">
   <input type="hidden" id="first" name="first" value="{{ $first }}"> 
   <input type="hidden" id="firstQuestion" name="firstQuestion" value="{{ $firstQuestion }}">  
   <input type="hidden" id="lastQuestion" name="lastQuestion" value="{{ $lastQuestion }}">

Method 2

Well of course… The issue was the iCheck jquery plugin and more specifically a selector. I made some modifications yesterday and changed the selector from input.line to input. That had as a result to select more input fields that it was supposed to. Anyway now its fixed.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x