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

  • Home
  • SEARCH
  • 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 168579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:28:42+00:00 2026-05-11T12:28:42+00:00

Please help me to refactore this Javascript code. There is big form for scheduled

  • 0

Please help me to refactore this Javascript code. There is big form for scheduled message sending(send date, reccurence type, end by date/qauntity, credits system – need to count total cost of scheduled sending plan in runtime). I’m writing Javascript validator for this form.

There is an validation algorithm 1) check if send date time is not in past moment 2) check if ‘end by date’ field time is greater then first send date time 3) validate total cost of schedule plan

(There about 6 steps, but I just write here 3 of them – I think it will be enough to grasp the problem)

‘Save scheduled plan’ button has a javascript listener on ‘click’ event. This listener calls this function:

ScheduledValidator.checkIfSendDateTimeIsNotInPast(params, form); 

Here is it its declaration:

ScheduledValidator.checkIfSendDateTimeIsNotInPast = function (params, form) {     var conn = new Ext.data.Connection();      conn.request({         url: CONST.BASE_URL + 'url',         params: params,         callback: function (options, success, response) {             response = Ext.util.JSON.decode(response.responseText);             if (response.success == false) {                 // display error messages             } else {                  ScheduledValidator.checkIfEndDateIsGreaterThatSendDate(params, form);             }         }     }); } 

We have nested request later:

ScheduledValidator.checkIfEndDateIsGreaterThatSendDate = function (params, form) { var conn = new Ext.data.Connection();  conn.request({     url: CONST.BASE_URL + 'url2',     params: params,     messageForm: form,     callback: function (options, success, response) {         response = Ext.util.JSON.decode(response.responseText);         if (response.success == false) {             // display error messages         } else {             ScheduledValidator.validateTotalCost(params, form);         }     } }); } 

and one more here:

ScheduledValidator.validateTotalCost = function (params, form) { ... 

I don’t like in that approach, that it is quite hard to understand the algorithm at first glance. Maybe it is not good, to make many(about 6) nested AJAX queries for validation of single form? Maybe it should be merged to the single request and after that we will do all the validation activities at server side? How should I refactor this code?

  • 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. 2026-05-11T12:28:43+00:00Added an answer on May 11, 2026 at 12:28 pm

    I suggest you zoom out and evaluate how the form process and user experience works before refactoring your code.

    For instance, is it necessary to give feedback to the user immediately when inputting dates? Can it wait until she’s completed filling out the form? If so, you can just use a regular form post, validate the submission server-side, and return feedback.

    If not, and the experience requires immediate feedback, you may want to look into creating a generic wrapper around your implementation to handle form validation. This can be done manually, or you can look around on Google for form validation mechanisms that allow you define specific URLs and callbacks, per your needs.

    A third option could be to do the validation client-side without contacting the server. Determine whether your logic can be done in Javascript (most likely, if it involves date calculations, this shouldn’t be too hard) and try to add a layer that does that for you so you don’t need to contact the server in the first place. Bonus: depending on how fast your server side code responds, this could actually improve the user experience (However, remember that server-side validation is still a must!).

    From the example use case you gave in your question, it sounds like my former suggestion applies — namely that it’s not entirely necessary to be so immediate in your feedback on whether the form is being filled out correctly. If my understanding of your situation is correct, I would advise starting the refactoring process by removing the AJAX calls and having it work as a normal form, and then adding in client-side-only validation once that works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 95k
  • Answers 95k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As much as I love XAML, for this kinds of… May 11, 2026 at 7:00 pm
  • Editorial Team
    Editorial Team added an answer You cannot iterate over them directly, but you can find… May 11, 2026 at 7:00 pm
  • Editorial Team
    Editorial Team added an answer I can answer this part of your question: Is there… May 11, 2026 at 7:00 pm

Related Questions

Hi Guys could you please help me refactor this so that it is sensibly
Can you help me refactor this code: public void keyPressed(KeyEvent e) { if (e.getKeyCode()==39)
Please help me to implement Factory design pattern for the task. I working on
I am pretty new to php and could sure use some help understanding how

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.