Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8183927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:19:24+00:00 2026-06-07T01:19:24+00:00

I have a view called contact.html.twig. It has a form with some textfields. I

  • 0

I have a view called contact.html.twig. It has a form with some textfields. I want to use javascript to validate that none of the fields are empty, as well as some other rules. But I do not know where to put the .js with the definitions. I do not know either how to call the .js script using the Twig notation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:19:26+00:00Added an answer on June 7, 2026 at 1:19 am

    This is a generic answer for how to handle javascript… not specifically the validation part. The approach I use is to store individual functionality in separate JS files as plugins in the bundles Resources/public/js directory like so:

    (function ($) {
    
        $.fn.userAdmin = function (options) {
            var $this = $(this);
    
            $this.on('click', '.delete-item', function (event) {
                event.preventDefault();
                event.stopPropagation();
    
                // handle deleting an item...
            });
        }
    });
    

    I then include these files in my base template using assetic:

    {% javascripts
        '@SOTBCoreBundle/Resources/public/js/user.js'
    %}
        <script src="{{ asset_url }}"></script>
    {% endjavascripts %}
    

    In my base template I have a block at the end of <body> for a $(document).ready();

    <script>
        $(document).ready(function () {
            {% block documentReady %}{% endblock documentReady %}
        });
    </script>
    </body>
    

    Then in my page that has the “user admin” functionality I can call the userAdmin function like so:

    {% block documentReady %}
        {{ parent() }}
        $('#user-form').userAdmin();
    {% endblock documentReady %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a partial view called Login.ascx that has my login boxes that I
I have a view and template called index.html. I have a image which is
I have some regular alert views and a custom alert view called 'UINotificationAlertView' I
I have a view that could be called from any of 3 actions from
I have a view called DashboardView that instantiates multiple WidgetView s. Each widget needs
Let's say I have some view called My View. I know I can create
I have a view called send_confirmation email - which basically sends emails. I want
I have an application that works some what similar to how iPhone's Contact application
I have a view called, clients which shows a list of calls from the
General context : MVVM application. I have a View called JobView. Its DataContext is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.