mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-29 13:38:44 +02:00
N°7063 - Forms SDK - Add Symfony forms component
error forms issue
This commit is contained in:
@@ -3,36 +3,23 @@
|
||||
namespace Combodo\iTop\FormSDK\Controller;
|
||||
|
||||
use Combodo\iTop\Controller\AbstractAppController;
|
||||
use Combodo\iTop\FormSDK\Helper\SelectHelper;
|
||||
use Combodo\iTop\FormSDK\Service\FormManager;
|
||||
use Dict;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Validator\Constraints\Length;
|
||||
use utils;
|
||||
|
||||
class TestController extends AbstractAppController
|
||||
{
|
||||
|
||||
|
||||
#[Route('/lucky/number/{max}', name: 'app_lucky_number')]
|
||||
public function number(Request $oRequest, int $max): Response
|
||||
{
|
||||
$number = random_int(0, $max);
|
||||
|
||||
return $this->render('test.html.twig', [
|
||||
'number' => $number
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/success', name: 'app_success')]
|
||||
public function success(): Response
|
||||
{
|
||||
return $this->render('formSDK/success.html.twig');
|
||||
}
|
||||
|
||||
#[Route('/form', name: 'app_form')]
|
||||
#[Route('/formSDK/test_Form', name: 'formSDK_test_form')]
|
||||
public function form(Request $oRequest, FormManager $oFormManager): Response
|
||||
{
|
||||
// retrieve DB Object
|
||||
@@ -50,9 +37,38 @@ class TestController extends AbstractAppController
|
||||
$oObjectPlugin->AddAttribute('name');
|
||||
$oObjectPlugin->AddAttribute('mobile_phone');
|
||||
// others data
|
||||
$oFormFactory->AddText('data1', ['label' => 'Ma ville'], 'Autun');
|
||||
$oFormFactory->AddText('data1', ['label' => 'Ma ville', 'constraints' => new Length(['min' => 3])], 'Autun');
|
||||
$oFormFactory->AddText('data2', ['label' => 'Pays'], 'FRANCE');
|
||||
$oFormFactory->AddSelect('data3', ['label' => 'Language', 'choices' => SelectHelper::GetApplicationLanguages()], 'FR FR');
|
||||
|
||||
$aSelectOptions = [
|
||||
'ajax_url' => $this->generateUrl('formSDK_ajax_select'),
|
||||
'valueField' => 'breed',
|
||||
'labelField' => 'breed',
|
||||
'searchField' => 'breed',
|
||||
'preload' => true,
|
||||
];
|
||||
$oFormFactory->AddSelect('data3', [
|
||||
'label' => 'Mon Chien',
|
||||
'placeholder' => 'Sélectionnez un chien',
|
||||
'attr' => [
|
||||
'data-widget' => 'Select',
|
||||
'data-widget-options' => json_encode($aSelectOptions)
|
||||
],
|
||||
// 'choice_loader' => new CallbackChoiceLoader(function(): array {
|
||||
//
|
||||
// $curl_data = utils::DoPostRequest('http://localhost/' . $this->generateUrl('formSDK_ajax_select'), []);
|
||||
// $response_data = json_decode($curl_data);
|
||||
//
|
||||
// if(count($response_data->items) > 2) return [];
|
||||
//
|
||||
// $result = [];
|
||||
// foreach ($response_data->items as $e) {
|
||||
// $result[$e->breed] = $e->breed;
|
||||
// }
|
||||
//
|
||||
// return $result;
|
||||
// }),
|
||||
], null);
|
||||
|
||||
// get the form
|
||||
$oForm = $oFormFactory->GetForm();
|
||||
@@ -72,9 +88,29 @@ class TestController extends AbstractAppController
|
||||
}
|
||||
|
||||
return $this->render('formSDK/form.html.twig', [
|
||||
'form' => $oFormFactory->GetForm(),
|
||||
'form' => $oForm->createView(),
|
||||
'theme' => 'formSDK/themes/portal.html.twig'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#[Route('/formSDK/ajax_select', name: 'formSDK_ajax_select')]
|
||||
public function ajax(Request $oRequest): Response
|
||||
{
|
||||
$oJson = file_get_contents('sources/FormSDK/Resources/dogs.json');
|
||||
$aDogs = json_decode($oJson, true);
|
||||
|
||||
$sQuery = $oRequest->request->get('query');
|
||||
|
||||
return new JsonResponse([
|
||||
"items" => $aDogs['dogBreeds']
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/success', name: 'app_success')]
|
||||
public function success(): Response
|
||||
{
|
||||
return $this->render('formSDK/success.html.twig');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user