Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Question 1 of 60 · Controlled and uncontrolled components · Easy
In React, what makes a form input a controlled component?
Not quite. Try another option.
Answer: Its value is managed by React state
A controlled input receives its value from React state and updates that state through an event handler.
Question 2 of 60 · Controlled and uncontrolled components · Easy
Which React feature is commonly used to access the current value of an uncontrolled input?
Not quite. Try another option.
Answer: A React ref
A ref provides direct access to the DOM input, allowing its current value to be read when needed.
Question 3 of 60 · Form state management patterns · Easy
Which React Hook is commonly used to manage a simple form field value?
Not quite. Try another option.
Answer: useState
useState stores a field value and provides a function for updating it.
Question 4 of 60 · Form state management patterns · Easy
What is a common way to manage several related form fields in one state value?
Not quite. Try another option.
Answer: Store the fields in an object
An object can group related field values, such as name, email, and phone, in one state value.
Question 5 of 60 · Handling form submission workflows · Easy
Which form event is normally handled when a React form is submitted?
Not quite. Try another option.
Answer: onSubmit
The form's onSubmit handler runs when the user submits the form.
Question 6 of 60 · Handling form submission workflows · Easy
Why is event.preventDefault() commonly called in a React form submission handler?
Not quite. Try another option.
Answer: To stop the default page reload
event.preventDefault() prevents the browser's normal form submission behavior, which usually reloads or navigates the page.
Question 7 of 60 · Reusable form component design · Easy
How can a reusable input component receive its label text?
Not quite. Try another option.
Answer: Through a prop
Props allow a reusable component to receive configurable values such as labels, names, and input types.
Question 8 of 60 · Reusable form component design · Easy
What is a key benefit of creating reusable form field components?
Not quite. Try another option.
Answer: They keep field behavior consistent
Reusable components help apply consistent structure, styling, accessibility, and error display across fields.
Question 9 of 60 · Conditional rendering in form interfaces · Easy
What does conditional rendering allow a React form to do?
Not quite. Try another option.
Answer: Show elements based on current state
Conditional rendering displays or hides interface elements according to values such as errors, selections, or loading state.
Question 10 of 60 · Conditional rendering in form interfaces · Easy
Which JSX expression displays an error message only when error has a truthy value?
Not quite. Try another option.
Answer: error && <span>Error</span>
With the && operator, the element on the right is rendered only when error is truthy.
Question 11 of 60 · Accessibility considerations in form handling · Easy
Which HTML element should identify the purpose of a form input for users and assistive technologies?
Not quite. Try another option.
Answer: <label>
A properly associated <label> gives an input an accessible name and makes the form easier to understand.
Question 12 of 60 · Accessibility considerations in form handling · Easy
Which attribute can indicate to assistive technologies that an input currently has an invalid value?
Not quite. Try another option.
Answer: aria-invalid
aria-invalid="true" communicates that the current input value has failed validation.
Question 13 of 60 · Client-side form validation concepts · Easy
Where does client-side form validation normally run?
Not quite. Try another option.
Answer: In the user's browser
Client-side validation runs in the browser and can provide feedback before data is sent to a server.
Question 14 of 60 · Client-side form validation concepts · Easy
Why should an application still validate form data on the server?
Not quite. Try another option.
Answer: Client-side checks can be bypassed
Client-side validation improves usability, but server-side validation is still required because requests can bypass browser checks.
Question 15 of 60 · Commonly used validation patterns · Easy
Which validation rule checks that a field is not left empty?
Not quite. Try another option.
Answer: Required-field validation
Required-field validation ensures that the user provides a value before submitting the form.
Question 16 of 60 · Commonly used validation patterns · Easy
Which validation pattern is commonly used for a password confirmation field?
Not quite. Try another option.
Answer: Check that both password values match
Password confirmation validation compares the two entered values and reports an error when they differ.
Question 17 of 60 · Schema-based validation principles · Easy
What does a validation schema describe?
Not quite. Try another option.
Answer: The expected shape and rules of data
A validation schema defines expected fields, data types, and constraints such as minimum lengths.
Question 18 of 60 · Schema-based validation principles · Easy
What is one benefit of using a shared validation schema?
Not quite. Try another option.
Answer: It centralizes validation rules
A shared schema keeps related validation requirements together and makes them easier to reuse and maintain.
Question 19 of 60 · Form validation using Zod · Easy
Which Zod expression defines a required string value?
Not quite. Try another option.
Answer: z.string()
z.string() creates a Zod schema that accepts string values.
Question 20 of 60 · Integrating schema validation with form logic and error handling · Easy
What is a useful result of calling Zod's safeParse when validating form data?
Not quite. Try another option.
Answer: A result indicating success or validation errors
safeParse returns a result object that can be checked for success and used to display validation errors without throwing an exception.
Question 21 of 60 · Controlled and uncontrolled components · Medium
A React text input receives its value from component state. Users can type into the input, but the displayed text never changes. Which change most directly fixes the problem?
Not quite. Try another option.
Answer: Add an onChange handler that updates the state
A controlled input displays the value stored in React state. Its onChange handler must update that state when the user types.
Question 22 of 60 · Controlled and uncontrolled components · Medium
A form contains a file input and should access the selected file only when the user submits the form. Which approach is most appropriate?
Not quite. Try another option.
Answer: Access the file input through a React ref
File inputs are typically handled as uncontrolled components. A ref can access the input's files collection during submission.
Question 23 of 60 · Form state management patterns · Medium
A form stores all field values in one object named formData. Which update correctly changes only the email field without removing the other fields?
Not quite. Try another option.
Answer: setFormData({ ...formData, email: value })
Spreading formData preserves its existing properties, while the later email property replaces only that field's value.
Question 24 of 60 · Form state management patterns · Medium
Several inputs share one change handler and each input has a unique name attribute. Which expression should the handler use to update the matching property in state?
Computed property syntax uses the input's name value as the state key, allowing one handler to update multiple fields.
Question 25 of 60 · Handling form submission workflows · Medium
A React form should validate data and send it with fetch without causing a page reload. What should the submit handler do first?
Not quite. Try another option.
Answer: Call event.preventDefault()
preventDefault() stops the browser's native form submission, allowing React code to validate and submit the data asynchronously.
Question 26 of 60 · Handling form submission workflows · Medium
A registration form sends an asynchronous request. Which workflow best prevents accidental duplicate submissions?
Not quite. Try another option.
Answer: Disable submission while the request is pending
Tracking a pending state and disabling submission prevents repeated requests while preserving the entered data and validation feedback.
Question 27 of 60 · Reusable form component design · Medium
A reusable TextField component must display a label, an input, and an error message. Which API best supports reuse across forms?
Not quite. Try another option.
Answer: Accept label, input props, and an error prop
A reusable field should receive its content, input behavior, and error state through props rather than hard-coding form-specific details.
Question 28 of 60 · Reusable form component design · Medium
A custom input component must allow its parent form to focus the underlying DOM input after validation fails. Which React design is most suitable?
Not quite. Try another option.
Answer: Expose the input by forwarding a ref
Ref forwarding lets a parent access the underlying input for imperative actions such as focusing the first invalid field.
Question 29 of 60 · Conditional rendering in form interfaces · Medium
A shipping-address section should appear only when useBillingAddress is false. Which JSX condition expresses this requirement?
Not quite. Try another option.
Answer: !useBillingAddress && <ShippingFields />
With logical AND rendering, the section is rendered only when the left operand is truthy. Negating the flag makes that occur when it is false.
Question 30 of 60 · Conditional rendering in form interfaces · Medium
A form conditionally removes a required companyName field when the user selects "Personal account". What should the form logic generally do with that hidden field?
Not quite. Try another option.
Answer: Exclude it from active validation and submission
A field that is not applicable should normally be excluded from the active validation rules and submitted payload to avoid invisible blocking errors.
Question 31 of 60 · Accessibility considerations in form handling · Medium
A text input shows the error message "Email is required" in an element with id="email-error". Which input attribute best creates an accessible relationship to that message?
Not quite. Try another option.
Answer: aria-describedby="email-error"
aria-describedby associates the input with supplementary text, allowing assistive technology to announce the related error message.
Question 32 of 60 · Accessibility considerations in form handling · Medium
After a failed submission, which behavior most improves keyboard and screen-reader usability when several fields are invalid?
Not quite. Try another option.
Answer: Focus the first invalid field and expose its error
Moving focus to the first invalid field helps users locate the problem, while an associated error message explains how to correct it.
Question 33 of 60 · Client-side form validation concepts · Medium
A checkout form validates card details in the browser before sending them to the server. Why must the server still validate the submitted data?
Not quite. Try another option.
Answer: Client-side validation can be bypassed or manipulated
Browser validation improves user experience but is not a security boundary. Requests can be modified or sent without using the form.
Question 34 of 60 · Client-side form validation concepts · Medium
A form currently displays validation errors after every keystroke, distracting users before they finish typing. Which strategy offers a more balanced experience?
Not quite. Try another option.
Answer: Validate a field on blur, then revalidate it on change
Validating initially on blur avoids premature errors. Revalidating an invalid field on change gives timely feedback as the user fixes it.
Question 35 of 60 · Commonly used validation patterns · Medium
A password confirmation field must match the password field. What kind of validation is required?
Not quite. Try another option.
Answer: A cross-field equality check
The confirmation value must be compared with another field's value, so validation must consider the relationship between both fields.
Question 36 of 60 · Commonly used validation patterns · Medium
A form accepts an optional website URL. Which rule correctly handles an empty value?
Not quite. Try another option.
Answer: Allow empty input; otherwise require a valid URL
Optional fields may be empty, but when a value is provided it should still satisfy the field's format requirements.
Question 37 of 60 · Schema-based validation principles · Medium
A team uses the same user schema to validate form data and infer TypeScript types. What is the main benefit of this approach?
Not quite. Try another option.
Answer: It reduces drift between runtime rules and static types
Deriving types from a schema keeps compile-time expectations aligned with the rules that validate actual runtime values.
Question 38 of 60 · Schema-based validation principles · Medium
A signup form requires password and confirmPassword to match. Why is object-level schema validation appropriate?
Not quite. Try another option.
Answer: The rule depends on values from multiple fields
A matching-password rule compares two properties, so it belongs at the object level where both values are available.
Question 39 of 60 · Form validation using Zod · Medium
Given const schema = z.object({ age: z.coerce.number().int().min(18) }), what happens when it validates { age: "21" }?
Not quite. Try another option.
Answer: It succeeds and produces the number 21
z.coerce.number() converts the numeric string to a number before applying the integer and minimum-value checks.
Question 40 of 60 · Integrating schema validation with form logic and error handling · Medium
A submit handler uses const result = schema.safeParse(formData). What should it do when result.success is false?
Not quite. Try another option.
Answer: Map validation issues to fields and skip submission
safeParse returns structured issues instead of throwing. The form can map issue paths to field errors and avoid sending invalid data.
Question 41 of 60 · Controlled and uncontrolled components · Hard
A file input is implemented as a controlled React input by assigning value={fileName} and updating fileName after onChange. What is the most accurate issue with this design?
Not quite. Try another option.
Answer: Browsers prohibit programmatically setting a file input's value to a nonempty path
For security reasons, browsers prevent scripts from assigning a nonempty local path to a file input. File inputs are usually treated as uncontrolled and accessed through a ref or the submitted form data.
Question 42 of 60 · Controlled and uncontrolled components · Hard
A controlled text input initially receives value={undefined} and later receives value="admin@example.com". Which behavior should be expected?
Not quite. Try another option.
Answer: React may warn about switching from uncontrolled to controlled
An undefined value means the input is initially uncontrolled. Supplying a defined value later switches it to controlled, which React warns against because it can produce inconsistent state ownership.
Question 43 of 60 · Form state management patterns · Hard
A form stores values, touched, errors, isSubmitting, and submitError in separate state variables. Several event handlers update multiple variables based on the previous form state. Which refactoring most directly reduces inconsistency risk?
Not quite. Try another option.
Answer: Use one reducer with explicit form-state actions
A reducer centralizes related transitions such as field changes, blur events, validation, submission start, and submission completion. This makes coordinated updates explicit and avoids stale or partially updated state.
Question 44 of 60 · Form state management patterns · Hard
A field update handler is written as setValues({ ...values, [name]: value }), and two updates are queued during the same event. What change best guarantees that both updates use the latest state?
Not quite. Try another option.
Answer: Use setValues(current => ({ ...current, [name]: value }))
The functional updater receives the most recent state at update time. Spreading a closed-over values object can overwrite another queued update when multiple changes are batched.
Question 45 of 60 · Handling form submission workflows · Hard
A React form submits data through fetch, but the page still navigates and the browser performs a native submission. Which correction is required?
Not quite. Try another option.
Answer: Call event.preventDefault() at the start of the submit handler
The browser's default submit action causes navigation. Calling preventDefault() before asynchronous work cancels that action so the handler can control the submission workflow.
Question 46 of 60 · Handling form submission workflows · Hard
A user submits a form twice before the first request finishes. Which design most reliably prevents an older response from overwriting newer state?
Not quite. Try another option.
Answer: Track a request identifier and accept only the latest response
Concurrent requests can resolve out of order. A request identifier, often combined with AbortController, lets the component ignore responses that no longer represent the current submission.
Question 47 of 60 · Reusable form component design · Hard
A reusable TextField component needs to support labels, descriptions, errors, arbitrary input attributes, and stable accessibility relationships. Which API design is strongest?
Not quite. Try another option.
Answer: Accept an explicit id, render a linked label, and derive described-by IDs
An explicit stable ID allows the label, description, and error message to reference the correct control. Forwarding relevant attributes also keeps the component reusable without sacrificing semantics.
Question 48 of 60 · Reusable form component design · Hard
A reusable form component exposes onSubmit, onChange, and errors, but it also silently converts server errors into local field errors. What is the main design concern?
Not quite. Try another option.
Answer: The component mixes presentation with an undocumented error policy
A reusable component should define clearly whether it owns validation, maps server errors, or merely displays them. Hidden mutation of error state makes integration behavior difficult to predict and test.
Question 49 of 60 · Conditional rendering in form interfaces · Hard
A billing address section is conditionally removed when sameAsShipping becomes true. When it is shown again, its previous values are gone. Which explanation is most accurate?
Not quite. Try another option.
Answer: Unmounting removes the component instance and its local state
When a subtree is removed, React discards state owned by components in that subtree. Preserve the values in a parent or external form state if they must survive conditional visibility.
Question 50 of 60 · Conditional rendering in form interfaces · Hard
A payment form renders card fields when method === "card" and bank fields otherwise. Both branches contain an input with the same position but different meanings. What prevents React from incorrectly reusing field state?
Not quite. Try another option.
Answer: Use distinct key values for the mutually exclusive branches
Distinct keys tell React that the branches represent different component identities. React can then reset branch-specific state instead of reusing state from the previous payment method.
Question 51 of 60 · Accessibility considerations in form handling · Hard
A field has an inline validation message that appears after blur. Which implementation best communicates the error to assistive technologies?
Not quite. Try another option.
Answer: Associate the message with aria-describedby and set aria-invalid="true"
The invalid state identifies the problem, while aria-describedby connects the control to its explanation. A visual color change alone is insufficient, and announcing every keystroke can be disruptive.
Question 52 of 60 · Accessibility considerations in form handling · Hard
A form displays a server-side error summary after submission. What behavior most improves keyboard and screen-reader usability?
Not quite. Try another option.
Answer: Move focus to a focusable summary heading and preserve field associations
Moving focus to the summary makes the new error state discoverable. The summary should also link to affected fields, whose individual messages remain associated through accessible descriptions.
Question 53 of 60 · Client-side form validation concepts · Hard
Why should client-side validation be treated as a usability feature rather than a security boundary?
Not quite. Try another option.
Answer: Users can bypass or modify all browser-executed validation logic
Client-side code runs in an environment controlled by the user. It can provide immediate feedback, but the server must independently validate and authorize every submitted value.
Question 54 of 60 · Commonly used validation patterns · Hard
A password confirmation rule reports an error while the user is still typing the first password. Which validation strategy generally gives the best experience without weakening final correctness?
Not quite. Try another option.
Answer: Validate confirmation on blur and again on submit
Cross-field errors are usually less distracting when shown after the field has been visited. Revalidating on submit ensures the final values are checked even if the user never blurred the field.
Question 55 of 60 · Commonly used validation patterns · Hard
A numeric field accepts "", "0", and "12" as strings. Which approach avoids incorrectly treating zero as missing while still recognizing an empty field?
Not quite. Try another option.
Answer: Trim first, then test explicitly for an empty string
Falsy checks classify numeric zero as missing after coercion. Explicitly testing the normalized string for "" distinguishes an empty value from the valid numeric value zero.
Question 56 of 60 · Schema-based validation principles · Hard
A schema is used both to validate a form and to transform a text field into a number. What architectural property is most important when using the parsed result?
Not quite. Try another option.
Answer: The application should use the schema's parsed output as trusted shape-checked data
Schema parsing can validate, normalize, and transform input. Using its output ensures downstream logic receives the type and structure the schema guarantees rather than an unchecked raw object.
Question 57 of 60 · Schema-based validation principles · Hard
A registration schema validates password and confirmPassword independently, but never checks that they match. What kind of rule is missing?
Not quite. Try another option.
Answer: An object-level refinement involving multiple fields
The equality constraint depends on two properties simultaneously. It belongs at the object level, where the validator can compare both values and attach the issue to the confirmation field.
Question 58 of 60 · Form validation using Zod · Hard
In Zod, a form field is received from an HTML input as a string, but the domain model requires a positive integer. Which schema best expresses the requirement?
Not quite. Try another option.
Answer: z.coerce.number().int().positive()
HTML inputs provide string values. z.coerce.number() converts numeric strings before applying integer and positivity checks, whereas z.number() expects a number already.
Question 59 of 60 · Form validation using Zod · Hard
A Zod object uses .refine() to ensure confirmPassword matches password, but the resulting issue appears at the form root. Which option gives the best field-level error display?
Not quite. Try another option.
Answer: Provide a path containing "confirmPassword" in the refinement options
Zod refinements can specify an issue path. Assigning the issue to confirmPassword lets form logic map it directly to that field's error message.
Question 60 of 60 · Integrating schema validation with form logic and error handling · Hard
A form calls schema.parse(values) inside an asynchronous submit handler. Invalid input throws before the handler can populate field errors. Which integration pattern is appropriate?
Not quite. Try another option.
Answer: Use safeParse and map result.error.issues into field errors
safeParse returns a success or failure result instead of throwing. On failure, issue paths can be converted into field-specific errors; transport and server errors can remain separate.
That's unit 4
Answer a few questions and your score shows up here.
Nearly through. Did unit 4 of INT252 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 4 of INT252 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.