I'm working in mvc. This is my view:
@using (Html.BeginForm("CreatePost", "Posts", FormMethod.Post, new { @enctype = "multipart/form-data", @id = "save-post-form" }))
{
<div class="row">
<div class="col-xs-5" id="post-details-div">
<div class="form-group">
<label>Post Title</label>
@Html.TextBoxFor(m => m.Title, new { @class = "form-control", @autocomplete = "off" })
@Html.ValidationMessageFor(m => m.Title, null, new { @class = "text-danger" })
</div>
<div class="form-group">
<label>Post Description</label>
@Html.TextAreaFor(m => m.Description, new { @class = "form-control", @autocomplete = "off" })
@Html.ValidationMessageFor(m => m.Description, null, new { @class = "text-danger" })
</div>
<div class="form-group">
<label>Post Cover Picture</label>
@Html.TextBoxFor(m => m.PostCoverFile, new { @type = "file" })
@Html.ValidationMessageFor(m => m.PostCoverFile, null, new { @class = "text-danger" })
</div>
</div>
<div id="post-content-div">
<label>Content</label>
<div class="form-group">
@Html.TextAreaFor(m => m.Content)
@Html.ValidationMessageFor(m => m.Content, null, new { @class = "text-danger" })
</div>
</div>
</div>
}
@section scripts{
<script>
require(["createPost"], function (module) {
$("#navbar-links").find("li[data-name='posts']").addClass('active');
module.load();
});
</script>
}
And this is my js file. I have only the form validation. I'm using require js:
define(["jquery", "mainModule", "ckeditor", "jqueryValidateUnobtrusive", "bootstrapTagsInput", "typeAhead"], function ($, module, CKEDITOR) {
var bind = function () {
$(document).ready(function () {
console.log("ready");
$('#save-post-form').validate({
highlight: function (element) {
$(element).addClass('error');
$(element).removeClass('valid');
console.log("ceva");
},
unhighlight: function (element) {
$(element).removeClass('error');
$(element).addClass('valid');
console.log("ceva");
}
});
});
var createPostPage = {
load: function () {
bind();
}
}
return createPostPage;
});
Nothing happens and I don't know what is wrong... Please help me. The validation works, but the highlight won't trigger.