'class' => 'af-button btn btn-primary',
'crm-icon' => 'fa-check',
'ng-click' => 'afform.submit()',
+ 'ng-if' => 'afform.showSubmitButton',
'#children' => [
['#text' => E::ts('Submit')],
],
// do nothing and return early
if (empty($afformSubmissionData)) {
- // unset sid from args
- $this->args['sid'] = NULL;
return;
}
foreach ($ids as $index => $id) {
$this->_entityIds[$entity['name']][$index] = [
$idField => isset($result[$id]) ? $id : NULL,
- '_joins' => [],
+ 'joins' => [],
];
if (isset($result[$id])) {
$data = ['fields' => $result[$id]];
// preprocess submitted values
$entityValues = $this->preprocessSubmittedValues($this->values);
+ // get the submission information if we have submission id.
+ // currently we don't support processing of already processed forms
+ // return validation error in those cases
+ if (!empty($this->args['sid'])) {
+ $afformSubmissionData = \Civi\Api4\AfformSubmission::get(FALSE)
+ ->addWhere('id', '=', $this->args['sid'])
+ ->addWhere('afform_name', '=', $this->name)
+ ->addWhere('status_id:name', '=', 'Processed')
+ ->execute()->count();
+
+ if ($afformSubmissionData > 0) {
+ throw new \CRM_Core_Exception(ts('Submission is already processed.'));
+ }
+ }
+
// Call validation handlers
$event = new AfformValidateEvent($this->_afform, $this->_formDataModel, $this, $entityValues);
\Civi::dispatcher()->dispatch('civi.afform.validate', $event);
angular.merge(data[selectedEntity][selectedIndex].fields, _.cloneDeep(schema[selectedEntity].data || {}));
data[selectedEntity][selectedIndex].joins = {};
}
+
+ ctrl.showSubmitButton = displaySubmitButton(args);
+ };
+
+ function displaySubmitButton(args) {
+ if (args['sid'] && args['sid'].length > 0) {
+ return false;
+ }
+ return true;
};
// Used when submitting file fields