Commit 6601edaa authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan
Browse files

changed to add 'confirm' option to cancel, submitcancel and cancelbackcreate elements

parent 35de0929
......@@ -42,6 +42,26 @@ function pieform_element_cancelbackcreate(Pieform $form, $element) {
$backelement['value'] = $element['value'][1];
$submitelement = $element;
$submitelement['value'] = $element['value'][2];
if (isset($element['confirm']) && isset($element['confirm'][0])) {
$cancelelement['confirm'] = $element['confirm'][0];
}
else {
unset($cancelelement['confirm']);
}
if (isset($element['confirm']) && isset($element['confirm'][1])) {
$backelement['confirm'] = $element['confirm'][1];
}
else {
unset($backelement['confirm']);
}
if (isset($element['confirm']) && isset($element['confirm'][2])) {
$submitelement['confirm'] = $element['confirm'][2];
}
else {
unset($submitelement['confirm']);
}
return pieform_element_cancel($form, $cancelelement) . ' ' . pieform_element_submit($form, $backelement)
. ' ' . pieform_element_submit($form, $submitelement);
}
......
......@@ -38,6 +38,10 @@ function pieform_element_cancel(Pieform $form, $element) {
throw new PieformException('Cancel elements must have a value');
}
if (isset($element['confirm'])) {
$element['onclick'] = 'return confirm(' . json_encode($element['confirm']) . ');';
}
$attributes = $form->element_attributes($element);
$attributes = preg_replace('/name="(.*)"/', 'name="cancel_$1"', $attributes);
$attributes = preg_replace('/id="(.*)"/', 'id="cancel_$1"', $attributes);
......
......@@ -42,6 +42,18 @@ function pieform_element_submitcancel(Pieform $form, $element) {
$submitelement['value'] = $element['value'][0];
$cancelelement = $element;
$cancelelement['value'] = $element['value'][1];
if (isset($element['confirm']) && isset($element['confirm'][0])) {
$submitelement['confirm'] = $element['confirm'][0];
}
else {
unset($submitelement['confirm']);
}
if (isset($element['confirm']) && isset($element['confirm'][1])) {
$cancelelement['confirm'] = $element['confirm'][1];
}
else {
unset($cancelelement['confirm']);
}
return pieform_element_submit($form, $submitelement) . ' ' . pieform_element_cancel($form, $cancelelement);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment