I was wondering. It's not possible to put Javascript inside blade #if right? Is blade #if some form of php but using php code will be discouraged in view right? What should I do? Here's the logic of what I'm trying to achieve. Basically, what alternative ways are there to achieve what I'm trying to do? I'm trying to show button when the three conditions are met.
#if(isToday($one_parking_info->booking_data->m_bkl_end_date) && isBeforeElevenPM() && notEndInT($one_parking_info->booking_data->m_plots_address_city))
<button type="button" class="btn btn-primary btn-sm" onClick="cancelBooking('{{ $one_parking_info->booking_data->m_bkl_gov_id }}')">取消</button>
#endif
Blade is a form of php, so all work is done on the server. So you cannot call javascript functions inside #if expression. Instead you can run the functions in the controller and return a value to say if you should include the button or not or you can have a javascript to show or hide the button if you don't care if the users can find and show the button if they want.
Something like in your controller return view('your view')->with(['showButton' => $shouldShow) and in your view #if($shouldShow) and the rest of your code
Your js must be in public or a child, and would be something like this:
#if(isToday($one_parking_info->booking_data->m_bkl_end_date) && isBeforeElevenPM() && notEndInT($one_parking_info->booking_data->m_plots_address_city))
#include('script.js')
<button type="button" class="btn btn-primary btn-sm" onClick="cancelBooking('{{ $one_parking_info->booking_data->m_bkl_gov_id }}')">取消</button>
#endif
Another option could be <script src="{{ asset('js/scripts.js') }}"></script> instead of #include directive
i guess:
#if(isToday($one_parking_info->booking_data->m_bkl_end_date) && isBeforeElevenPM() && notEndInT($one_parking_info->booking_data->m_plots_address_city))
#include('script.js')
<button type="button" class="btn btn-primary btn-sm" data-id="{{ $one_parking_info->booking_data->m_bkl_gov_id }}">取消</button>
#endif
<script>
$('body').on('click','.btn-sm',function(){
var id = $(this).attr('data-id');
//
logic of cancelBooking
//
})
</script>
Related
I have a button , when i click on that button it should change it's text.it's there inside a foreach loop. But the problem is when i click on that button first buttons text change. I want to change the specific button text which i clicked ..How do i do that?
Front-End Part
#foreach($products as $product)
<button onclick="this.disabled=true; quoteAdd('{!!$product->id!!}')" id="inquireButton" class="btn btn-danger ">Inquire</button>
#endforeach
Javascript Part
function quoteAdd(productId)
{
$("#inquireButton").html('Save');
// other code ..
}
You need to pass button reference using this keyword to quoteAdd method like following.
PHP
#foreach($products as $product)
<button onclick="this.disabled=true; quoteAdd('{!!$product->id!!}', this)" id="inquireButton" class="btn btn-danger ">Inquire</button>
#endforeach
JS
function quoteAdd(productId, button) {
$(button).text('Save');
//other code ..
}
FYI id should be unique for each element.
The value of the id attribute in HTML should be unique, so basically what you are doing is wrong (you shouldn't have fixed id within a loop).
Regardless this issue, you can do the following:
// Front-End Part
#foreach($products as $product)
<button onclick="this.disabled=true; quoteAdd(this)" id="inquireButton_{!!$product->id!!}" class="btn btn-danger ">Inquire</button>
#endforeach
// Javascript Part
function quoteAdd(el)
{
$(el).html('Save');
// other code ..
}
I am working on Larvel framework. I am using login blade file of auth component. There is one button of register. whren i apply onclick on button to register page it is not redirect to register page.
<button class="btn btn-info sign-bttn" onclick="{{ url('/register') }}">Register Your Business</button>
Where i am doing wrong anyone help me
If you wanna redirect, should use a element of HTML
<a class="btn btn-info sign-bttn" href="{{ url('/register') }}">Register Your Business</a>
Btw, inside onclick you need to pass a javascript not a string ({{ url('/register') }} just pass a string)
Redriect in javascript use window.location.href
<button class="btn btn-info sign-bttn" onclick="window.location.href = '{{ url('/register') }}';">Register Your Business</button>
I need to use an asp.mvc form post. I use some angularjs on the client side. I know this question is not doing everything the "angular way".
What I need to do is set a variable $scope.IsUploadingData when the post happens so I can disable the buttons and show something to indicate progress. I have tried using ng-click, but it seems to stop the post from happening. Is there anyway to set the variable without interrupting the form post?
#using (Html.BeginFormAntiForgeryPost(Url.Action("Accept", "Members", new { area = "Testing" })))
{
other form stuff here
<span class="input-group-btn">
<button ng-disabled="IsUploadingData == true" name="accept" type="submit">Submit</button>
<button class="btn btn-default" ng-disabled="IsUploadingData == true" name="reject" type="submit">Reject</button>
<img ng-show="IsUploadingData" src="/SiteMedia/spinner[1].gif" />
</span>
}
It looks like you could use ng-submit to control the submission process and set $scope.IsUploadingData in the function you call from ng-submit. This is a decent write-up on ng-submit: http://learnwebtutorials.com/angularjs-tutorial-submitting-form-ng-submit
I have kendo grid where i am using anchor tag so using href i am trying to pass two params from client side but it always give syntax error, any help what is correct way to pass variables using href.
config.js
toolbar: [{template: '<a class="btn btn-default btn-sm pull-right"
href="app/challenge/rest/exportChallengeGridDataToExcel?key={{$rootScope.id}}
&challengeType={{$rootScope.challengeType}}">Export to Excel</a>'}]
You can do something like :
'<a class="btn btn-default btn-sm pull-right"
href="app/challenge/rest/exportChallengeGridDataToExcel?key={{$rootScope.id}}
&challengeType={{$rootScope.challengeType}}">Export to Excel</a>
Anyways I would encourage you to use $rootScope as less as possible, also to build your URL in your controller so your html looks more readable, but that's up to you
I have fetched task title from database. Now I want if I click on task title it should show description of that particular task on the same page using toggle.
I have tried AJAX and JavaScript but found no result. Can anyone help by providing a small example related to this topic?
<button type="button" id="button" value="submit" class="btn btn-warning" onclick="javascript:fload($usermm->id);">{{ $usermm->TaskTitle }}</button>
This should work:
<button type="button" id="button" value="submit" class="btn btn-warning" onclick="javascript:fload({{{ $usermm->id }}});">{{{ $usermm->TaskTitle }}}</button>
Use {{{ $usermm->TaskTitle }}} (3 curly brackets instead of 2) to make sure you escape the data in the view.
UPDATE
I'm not going to write all code for you but I can give you a clue:
function fload(id)
{
[...]
var url='mytaskurl?id=' +id;
[...]
}
UPDATE #2
Here is an example of using Ajax with Laravel:
http://blog.igeek.info/2013/using-ajax-in-laravel/