0

When I open a new form, all the js works, upon edit it fails to load all the internal js. Please work under the assumption that all of the data and routing is hooked up appropriately.

I've got a link to open a form with an existing object:

<a th:if="${foo.typeName} == a" href="Edit"
       th:href="@{/aFoo/{id}(id=${foo.id})}">view</a>

Controller methods:

New Object:

@RequestMapping(value="/aFoo", method=RequestMethod.GET)
    public String newAFooForm(Model model) {
        FooViewModel fooViewModel = new FooViewModel(Type.A);
        model.addAttribute("fooViewModel", fooViewModel);
        return "fooForm";
    }

Load Existing Object:

@RequestMapping(value="/aFoo/{id}", method=RequestMethod.GET)
    public String editAFooForm(@PathVariable("id") Long id, Model model) {
        FooViewModel fooViewModel = assignFooViewModel(id);
        model.addAttribute("fooViewModel", fooViewModel);
        return "fooForm";
    }

The form html/th code shouldn't matter, but to describe my js references:

layout.html is the container for both forms. It has the js imports:

<script th:src="@{js/jquery-1.11.3.min.js}"></script>
<script th:src="@{js/bootstrap.min.js}"></script>
<script th:src="@{js/parsley.min.js}"></script>

and a template for js on contained pages:

<div layout:fragment="script"></div>

fooForm.html has additional js imports, then a ton of js code, it starts:

<div layout:fragment="script">
    <script th:src="@{js/typeahead.bundle.min.js}"></script>
    <script th:src="@{js/handlebars.js}"></script>
    <script>
    ....
    </script>
</div>

My first thought is that I'm somehow writing the link wrong so it loses the context of the referenced js. Any thoughts? Thanks.

1
  • Post the generated HTML code for the script tag. Commented Jul 15, 2015 at 18:33

1 Answer 1

1

The js imports should have the format:

<script href="https://stackoverflow.com/js/handlebars.js" th:src="@{/js/handlebars.js}"></script>
Sign up to request clarification or add additional context in comments.

1 Comment

Not really. th:src is sufficient. also note href is not an attribute of script tag. You are missing something else here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.