1

Magento 2 Ui component Date Fields save the current date not saved the inputed date please show my below code

Form

 <field name="active_from_date" formElement="date">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="source" xsi:type="string">program</item>
            </item>
        </argument>
        <settings>
            <validation>
                <rule name="validate-date" xsi:type="boolean">true</rule>
            </validation>
            <dataType>text</dataType>
            <label translate="true">From</label>
            <dataScope>active_from_date</dataScope>
        </settings>
    </field>

    <field name="active_to_date" formElement="date">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="source" xsi:type="string">program</item>
            </item>
        </argument>
        <settings>
            <validation>
                <rule name="validate-date" xsi:type="boolean">true</rule>
            </validation>
            <dataType>text</dataType>
            <label translate="true">To</label>
            <dataScope>active_to_date</dataScope>
        </settings>
    </field>

and save action

 public function execute()
{
    $data = $this->getRequest()->getPostValue();

    $resultRedirect = $this->resultRedirectFactory->create();
    if ($data) {
        $id = $this->getRequest()->getParam('id');
        if ($id) {
            $model = $this->programRepository->getById($id);
        } else {
            unset($data['id']);
            $model = $this->programFactory->create();
        }

        try {
            $this->dataObjectHelper->populateWithArray($model, $data, ProgramInterface::class);
            $this->programRepository->save($model);
            $this->messageManager->addSuccessMessage(__('You saved this data.'));
            $this->_getSession()->setFormData(false);
            if ($this->getRequest()->getParam('back')) {
                return $resultRedirect->setPath('*/*/edit', ['id' => $model->getId(), '_current' => true]);
            }
            return $resultRedirect->setPath('*/*/');
        } catch (\Magento\Framework\Exception\LocalizedException $e) {
            $this->messageManager->addErrorMessage($e->getMessage());
        } catch (\RuntimeException $e) {
            $this->messageManager->addErrorMessage($e->getMessage());
        } catch (\Exception $e) {
            $this->messageManager->addException($e, __('Something went wrong while saving the data.'));
        }

        $this->_getSession()->setFormData($data);
        return $resultRedirect->setPath('*/*/edit', ['id' => $this->getRequest()->getParam('id')]);
    }
    return $resultRedirect->setPath('*/*/');
}

Please help me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.