MCPcopy
hub / github.com/streamlit/streamlit / submitForm

Method submitForm

frontend/lib/src/WidgetStateManager.ts:346–399  ·  view source on GitHub ↗

* Commit pending changes for widgets that belong to the given form, * and send a rerunBackMsg to the server.

(
    formId: string,
    fragmentId: string | undefined,
    actualSubmitButton?: WidgetInfo
  )

Source from the content-addressed store, hash-verified

344 * and send a rerunBackMsg to the server.
345 */
346 public submitForm(
347 formId: string,
348 fragmentId: string | undefined,
349 actualSubmitButton?: WidgetInfo
350 ): void {
351 if (!isValidFormId(formId)) {
352 // This should never get thrown - only FormSubmitButton calls this
353 // function.
354 // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
355 throw new Error(`invalid formID '${formId}'`)
356 }
357
358 const form = this.getOrCreateFormState(formId)
359
360 const submitButtons = this.formsData.submitButtons.get(formId)
361
362 let selectedSubmitButton
363
364 if (actualSubmitButton !== undefined) {
365 selectedSubmitButton = actualSubmitButton
366 }
367 // can have an empty list of submitButtons
368 else if (submitButtons !== undefined && submitButtons.length > 0) {
369 // click the first submit button. We can choose any so we just choose first.
370 selectedSubmitButton = submitButtons[0]
371 }
372
373 if (selectedSubmitButton) {
374 this.createWidgetState(selectedSubmitButton, {
375 fromUi: true,
376 }).triggerValue = true
377 }
378
379 // Copy the form's values into widgetStates, delete the form's pending
380 // changes, and send our widgetStates back to the server.
381 this.widgetStates.copyFrom(form.widgetStates)
382 form.widgetStates.clear()
383
384 this.sendUpdateWidgetsMessage(fragmentId)
385 this.syncFormsWithPendingChanges()
386
387 if (selectedSubmitButton) {
388 this.deleteWidgetState(selectedSubmitButton.id)
389 }
390
391 // If the form has the clearOnSubmit flag, we emit a signal to all widgets
392 // in the form. Each widget that handles this signal will reset to their
393 // default values, and submit those new default values to the WidgetStateManager
394 // in their signal handlers. (Because all of these widgets are in a form,
395 // none of these value submissions will trigger re-run requests.)
396 if (form.clearOnSubmit) {
397 form.formCleared.emit()
398 }
399 }
400
401 public setChatInputValue(
402 widget: WidgetInfo,

Callers 15

Slider.test.tsxFile · 0.80
Radio.test.tsxFile · 0.80
Checkbox.test.tsxFile · 0.80
TextArea.test.tsxFile · 0.80
DateInput.test.tsxFile · 0.80
TextInput.test.tsxFile · 0.80

Calls 9

getOrCreateFormStateMethod · 0.95
createWidgetStateMethod · 0.95
deleteWidgetStateMethod · 0.95
isValidFormIdFunction · 0.90
copyFromMethod · 0.80
getMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected