ContosoUniversityDotNetCore-Pages icon indicating copy to clipboard operation
ContosoUniversityDotNetCore-Pages copied to clipboard

Lodash doesn't seem correctly configured, can't submit with errors

Open terryaney opened this issue 4 years ago • 3 comments

I select an Instructor, go to the Edit page and clear everything out and hit save.

I then get a script error what _.reject() is not a function in showSummary().

I looked at your normal Contoso repo (I didn't pull/test) and noticed that the lodash folder has many more files in it instead of only core.js. I didn't see a libman.json to try and update the libraries, so not sure if I'm missing something and didn't build correctly (just hit F5 and it worked) or if there is a problem with the script.

Additionally, if I instead of clearing all inputs and submitting, I just append the letter 'a' to the date hire and submit. It submits successfully, redirects to listing page, but did not display error nor save bad data.

Side question when you look at this. Trying to understand where the ajax call submits to when clicking submit on Edit page. The form.action is undefined and I put break points in all the methods in CreateEdit.cshtml.cs and never hit any of them.

terryaney avatar Jan 15 '21 23:01 terryaney

Some packages got updated and I'm sure they could be fixed i.e bootstrap was upgraded to 4.3.1 but there's code that references bootstrap 3.3.7 (see pic ... I don't think the flash of validation is supposed to work that way). If I'm able to fix these while I learn more about this vertical slice architecture, I'll create a PR. error with validation

RickTheHat avatar Jan 24 '21 03:01 RickTheHat

I needed to move the following scripts to the header in order for it to work. Don't know why this should make a difference but it did.

<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/lodash/dist/core.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.js"></script>
<script src="~/js/site.js"></script>

TDK1964 avatar Jun 12 '21 16:06 TDK1964

Something in this method or sub-methods was throwing an error stating that it could not find _.reject(). I found this by adding the alert statement to the catch.

var highlightErrors = function (xhr) {
    try {
        var data = JSON.parse(xhr.responseText);
        highlightFields(data);
        showSummary(data);
        window.scrollTo(0, 0);
    } catch (e) {
        alert(e);
        // (Hopefully) caught by the generic error handler in `config.js`.
    }
};

To fix this, I had to replace the following.

<script src="~/lib/lodash/dist/core.js"></script>

with this

<script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script>

Hope this helps.

cdgipson avatar Jul 20 '21 10:07 cdgipson