Created
August 18, 2020 13:58
-
-
Save grandmanitou/376526c90eb070cbfa1d01a1aa56e421 to your computer and use it in GitHub Desktop.
Create preview button next to an url input, open in new tab -- Bootstrap 4 / Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).on('click', '.btn-preview-url', function(e) { | |
e.preventDefault(); | |
let element = $(this).data('src'); | |
let url = $(element).val(); | |
if (url !== '') { | |
window.open(url, '_blank'); | |
} | |
return false; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
<div class="form-group"> | |
<label for="website">{{ __('Website') }}</label> | |
<div class="input-group"> | |
<input type="text" id="website" name="website" value="{{ old('website') }}" class="form-control @error('website') is-invalid @enderror" placeholder="{{ __('Website') }}"> | |
<div class="input-group-append"> | |
<button class="btn btn-outline-secondary btn-preview-url" type="button" data-src="#website" class="">{{ __('Preview in new tab') }} <i class="fa fa-external-link"></i></button> | |
</div> | |
</div> | |
@error('website') <div class="invalid-feedback">{{ $message }}</div> @enderror | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment