I want to auto-generate slug when user input the title.
<div class="form-group">
<label for="name">Title of News</label>
<input type="text" class="form-control" id="name" name="name"
placeholder="Enter your title of news"
value="@if(isset($news->name)){{ old('name', $news->name) }}@else{{old('name')}}@endif">
</div>
<div class="form-group">
<label for="slug">Slug</label>
<input type="text" class="form-control" id="slug" name="slug"
placeholder="slug"
{{!! isFieldSlugAutoGenerator($dataType, $dataTypeContent, "slug") !!}}
value="@if(isset($news->name)){{ str_slug($news->name, '-') }}@endif">
</div>
<script>
$('document').ready(function () {
$('#slug').slugify();
});
</script>
Problem is:
It does not change real time when I enter text in
Title of news
.Because it does not change real time, it doesn't save slug correctly.
Example:
When I input in fields Title
of news: Apple iPhone 7
-> click button Save. The fields slug
not contain any values.
Next, I change Title
of news to Apple have plan release IOS 11
-> click button Save. The fields slug
in database change to Apple iPhone 7
.
You can see at gif: