NameAddress
Larry Fly (500)912 Merriman

Graphite Function Examples

G.view Example:

First Name: (first name)

Last Name: (last name)

Formatter Function Examples

2500.5

Picker Examples

G.view


G.view calls a backend function and allows the passing of variables
from the frontend to the backend. You can pass a javascript object 
or just pass parameters with a comma between them.

Example:

This is the front end code that runs for the Update Names button:
(this code has to be placed in an async function) 

try {
	const response = await G.view('MyBackendFunction', {"firstName": "Dylan", "lastName": "Wolverton"});
	let firstName = response.message[0]["firstName"];
	let lastName = response.message[0]["lastName"];
	$("#firstName").html(firstName);
	$("#lastName").html(lastName);
} catch(response) {
	Communicate.toast("error", `${response.message}`)
}


This is the backend function:

public function MyBackEndFunction($value){
	if($value) {
		$this->sendResponse(true, ['message'=> $value]);
	} else {
		$this->sendResponse(false, ['message'=>'bad news']);
	}
}
									

G.ajaxFormOnSubmit


G.ajaxFormOnSubmit is used to create an event that 
posts data to the backend and can run a 
backend function on form submit.

Example:

This is the frontend code that runs when clicking the form submit 
button on the G.ajaxFormOnSubmit Test form. 

G.ajaxFormOnSubmit({
	form: '#test',
	ajaxFunction: 'OnFormSubmit',
	errorMessage: "Failed to post data,",
	successMessage: false,
	loading: false,
	onSuccess: () => {
		const getCookie = (name) => {
			const value = `; ${document.cookie}`;
			const parts = value.split(`; ${name}=`);
			if (parts.length === 2) return parts.pop().split(';').shift();
		}
		Communicate.toast('success', 'Success', `${getCookie("postedData")} was posted`)
	}
});

This is the backend function that runs:

public function OnFormSubmit() {
	if($_POST["args"][0]["formData"]) {
		setcookie("postedData", $_POST["args"][0]["formData"]);
	} else {
		$this->sendResponse(false, ['message'=>'bad news']);
	}
}
									

Copyright © Graphite 5, all rights reserved.