Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use datetime field type as editable #6144

Merged
merged 1 commit into from Jul 25, 2020

Conversation

peter-gribanov
Copy link
Contributor

@peter-gribanov peter-gribanov commented Jun 15, 2020

Subject

In PR #6071 added hendleing a datetime field type to SetObjectFieldValueAction, but this type is not really editable.

Unfortunately, i want to say that it is not possible to use the datetime type as editable due to the conflict of dependencies in X-editable. Attempting to use the datetime type as editable will result in an error in JavaScript at this line.

Uncaught TypeError: Cannot read property 'parseFormat' of undefined
    at DateTime.initPicker (bootstrap-editable.min.js:6554)
    at new DateTime (bootstrap-editable.min.js:6522)
    at Object.createInput (bootstrap-editable.min.js:859)
    at Editable.init (bootstrap-editable.min.js:1498)
    at new Editable (bootstrap-editable.min.js:1477)
    at HTMLSpanElement.<anonymous> (bootstrap-editable.min.js:2139)
    at Function.each (jquery.js:374)
    at n.fn.init.each (jquery.js:139)
    at n.fn.init.$.fn.editable (bootstrap-editable.min.js:2125)
    at Object.setup_xeditable (Admin.js:211)

Attempting to update the X-editable code to the latest version (1.5.1 => 1.5.3) will fail. This code has not changed in the original library.

Problem due to dependency:

Based on smalot bootstrap-datetimepicker plugin. Before usage you should manually include dependent js and css:

<link href="css/datetimepicker.css" rel="stylesheet" type="text/css"></link> 
<script src="js/bootstrap-datetimepicker.js"></script>

The link indicates a project (bootstrap-datetime-picker) that is deprecated in favour of eonasdan-bootstrap-datetimepicker. The eonasdan-bootstrap-datetimepicker is already used in the SonataCoreBundle, but it is not compatible with X-editable.

For X-editable, the old version of the library is needed because the next line is there. X-editable breaks because variable $.fn.datetimepicker.DPGlobal is not defined.

Connecting both libraries is not possible. They will conflict.

I also updated the documentation because it is outdated.

Changelog

### Fixed
- Can't use `datetime` field type as editable

@peter-gribanov peter-gribanov force-pushed the datetime_editable branch 4 times, most recently from 7a52d18 to ad29f81 Compare June 16, 2020 10:53
core23
core23 previously approved these changes Jun 16, 2020
@core23 core23 requested a review from a team June 16, 2020 11:26
@core23 core23 added the minor label Jun 16, 2020
Copy link
Member

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update the available type in the doc with the TemplateRegistry constant instead ?

Also I would prefer to NOT add the deprecated type in the documentation,

  • text
  • smallint
  • bigint
  • decimal (float should be preferred)

@peter-gribanov
Copy link
Contributor Author

@VincentLanglet i did not want to remove supported types, although they are deprecated. But if you insist, i will remove them.

@VincentLanglet
Copy link
Member

@VincentLanglet i did not want to remove supported types, although they are deprecated. But if you insist, i will remove them.

The deprecated type are already removed from some part of the documentation.
All the deprecated type can be replace by another, there is an upgrade note about this.

I don't think it's a good idea to keep the doc about the deprecated type, because we don't want developers to use them. Plus, we'll certainly forget to update the doc in the next major if we don't remove them now.

@peter-gribanov peter-gribanov changed the title Register a datetime field type as editable Can't use datetime field type as editable Jun 16, 2020
@VincentLanglet
Copy link
Member

Thanks for the update @peter-gribanov

I that don't bother you, can you also replace
actions by ListMapper::TYPE_ACTIONS
batch by ListMapper::TYPE_BATCH
select by ListMapper::TYPE_SELECT
array by TemplateRegistry::TYPE_ARRAY
...

same for time, datetime, percent, ...

Let's promote the use of the new constant !

@peter-gribanov
Copy link
Contributor Author

peter-gribanov commented Jun 16, 2020

I updated the PR description. If something is not clear, please ask.

@peter-gribanov
Copy link
Contributor Author

Let's promote the use of the new constant !

I update documentation.

@VincentLanglet
Copy link
Member

Let's promote the use of the new constant !

I update documentation.

Thanks !

By looking at the X-editable repository, I discover that this is not maintained anymore
https://github.com/vitalets/x-editable#project-status

This will especially be a blocking point when we'll want to support boostrap 4.
Do you know this library @peter-gribanov ?

@VincentLanglet VincentLanglet requested a review from a team June 16, 2020 20:35
@peter-gribanov
Copy link
Contributor Author

By looking at the X-editable repository, I discover that this is not maintained anymore
https://github.com/vitalets/x-editable#project-status

This will especially be a blocking point when we'll want to support boostrap 4.
Do you know this library @peter-gribanov ?

Yes. I have seen that. This project has not been updated for more than a year. I do not know X-editable. You may have to abandon the live-edit function.

@VincentLanglet
Copy link
Member

By looking at the X-editable repository, I discover that this is not maintained anymore
https://github.com/vitalets/x-editable#project-status
This will especially be a blocking point when we'll want to support boostrap 4.
Do you know this library @peter-gribanov ?

Yes. I have seen that. This project has not been updated for more than a year. I do not know X-editable. You may have to abandon the live-edit function.

I created an issue for this discussion.
#6147

Feel free to add any information which can help :)

VincentLanglet
VincentLanglet previously approved these changes Jun 16, 2020
jordisala1991
jordisala1991 previously approved these changes Jun 16, 2020
@peter-gribanov
Copy link
Contributor Author

peter-gribanov commented Jun 17, 2020

@xleliberty can you comment this PR? Did editing datetime work for you?

@SonataCI
Copy link
Collaborator

Could you please rebase your PR and fix merge conflicts?

@xleliberty
Copy link
Contributor

Hi sorry, i didn't see this message before.
In fact my original pr works fine, but as long has we are sticked to SF 3.4 i am not able to test the latest tag code to verify in a 4.X branch.

sorry

@peter-gribanov
Copy link
Contributor Author

peter-gribanov commented Jul 18, 2020

@xleliberty this problem is not in Symfony and not in Sonata. This problem is that the X-editable datetime is not compatible with the bootstrap-datetimepicker version used in Sonata.

Maybe you are using a different version of bootstrap-datetimepicker or not using X-editable?

VincentLanglet
VincentLanglet previously approved these changes Jul 22, 2020
@VincentLanglet VincentLanglet self-requested a review July 22, 2020 21:52
@VincentLanglet
Copy link
Member

The link indicates a project (bootstrap-datetime-picker) that is deprecated in favour of eonasdan-bootstrap-datetimepicker. The eonasdan-bootstrap-datetimepicker is already used in the SonataCoreBundle, but it is not compatible with X-editable.

Can we make a PR on eonasdan-bootstrap-datetimepicker ?

For X-editable, the old version of the library is needed because the next line is there. X-editable breaks because variable $.fn.datetimepicker.DPGlobal is not defined.

Can't we add the missing line in our assets ?

@peter-gribanov
Copy link
Contributor Author

peter-gribanov commented Jul 23, 2020

Can we make a PR on eonasdan-bootstrap-datetimepicker ?

I don't think they would want to restore compatibility with a project that is no longer supported.

Can't we add the missing line in our assets ?

Not so simple. Also required UTCDate function and dates variable. But simply adding these variables doesn't solve the problem. Datetimepicker expects different behavior.

Uncaught Error: Could not initialize DateTimePicker without an input element
    at dateTimePicker (bootstrap-datetimepicker.js:2322)
    at HTMLDivElement.<anonymous> (bootstrap-datetimepicker.js:2364)
    at Function.each (jquery.js:374)
    at n.fn.init.each (jquery.js:139)
    at n.fn.init.$.fn.datetimepicker (bootstrap-datetimepicker.js:2359)
    at DateTime.render (bootstrap-editable.js:6557)
    at EditableForm.render (bootstrap-editable.js:91)
    at HTMLDivElement.<anonymous> (bootstrap-editable.js:410)
    at Function.each (jquery.js:374)
    at n.fn.init.each (jquery.js:139)

It looks like you need to rewrite the datetimepicker implementation in the X-editable. If you have the time and desire, you can always do it. I will not do it.

@VincentLanglet VincentLanglet requested a review from a team July 23, 2020 10:26
@SonataCI
Copy link
Collaborator

Could you please rebase your PR and fix merge conflicts?

correct documentation

add a time field options in documentation

remove deprecated field types from documentation

datetime field type is not editable

use constants in documentation

use constants for determinate a field type
@jordisala1991 jordisala1991 merged commit dca2a5a into sonata-project:3.x Jul 25, 2020
@jordisala1991
Copy link
Member

Thank you @peter-gribanov

@peter-gribanov peter-gribanov deleted the datetime_editable branch July 27, 2020 08:01
peter-gribanov added a commit to peter-gribanov/SonataAdminBundle that referenced this pull request Jul 27, 2020
peter-gribanov added a commit to peter-gribanov/SonataAdminBundle that referenced this pull request Jul 27, 2020
allow use data_transformer in SetObjectFieldValueAction

create BooleanToStringTransformer for allows to use non-strings

update SetObjectFieldValueActionTest

use yoda conditions

fix errors in HelperControllerTest

test BooleanToStringTransformer

allow override transformers for 'date', 'boolean' and 'choice' field types

mark BooleanToStringTransformer and BooleanToStringTransformer classes as final

add example of using the data_transformer option in docs

add full docs about Symfony Data Transformers

optimize resolve Data Transformer

fix docs

create DataTransformerResolver service

add type hint for BooleanToStringTransformer::$trueValue

allow add a custom global transformers

field type should be a string

correct default value for $globalCustomTransformers

correct test DataTransformerResolverTest::testAddCustomGlobalTransformer()

add BC support usage of DataTransformerResolver

Update tests/Action/SetObjectFieldValueActionTest.php

Update tests/Action/SetObjectFieldValueActionTest.php

Update tests/Form/DataTransformer/BooleanToStringTransformerTest.php

Update tests/Form/DataTransformer/BooleanToStringTransformerTest.php

Update tests/Form/DataTransformerResolverTest.php

Update tests/Form/DataTransformerResolverTest.php

Update src/Action/SetObjectFieldValueAction.php

change "entity" word to "model" in documentations

change deprecated error message

add datetime in editable date form types

correct test transform datetime and date form types

test DateTime object in assertSame()

fix typo

restore getTemplate() return value in SetObjectFieldValueActionTest

use Yoda conditions

lazy-load predefined data transformers

add DataTransformerResolverInterface

use constants for determinate a field type

test laze-load data transformers

test usage DataTransformerResolver::addCustomGlobalTransformer()

create simple function in DataTransformerResolverTest

Process deprecation of FieldDescriptionInterface::getTargetEntity()

Use FieldDescriptionInterface::getTargetModel if exists sonata-project#6208

change usage getTargetEntity() -> getTargetModel() in DataTransformerResolverTest

merge changes from PR sonata-project#6167

register BooleanToStringTransformer as a service

merge changes from PR sonata-project#6144
peter-gribanov added a commit to peter-gribanov/SonataAdminBundle that referenced this pull request Jul 27, 2020
allow use data_transformer in SetObjectFieldValueAction

create BooleanToStringTransformer for allows to use non-strings

update SetObjectFieldValueActionTest

use yoda conditions

fix errors in HelperControllerTest

test BooleanToStringTransformer

allow override transformers for 'date', 'boolean' and 'choice' field types

mark BooleanToStringTransformer and BooleanToStringTransformer classes as final

add example of using the data_transformer option in docs

add full docs about Symfony Data Transformers

optimize resolve Data Transformer

fix docs

create DataTransformerResolver service

add type hint for BooleanToStringTransformer::$trueValue

allow add a custom global transformers

field type should be a string

correct default value for $globalCustomTransformers

correct test DataTransformerResolverTest::testAddCustomGlobalTransformer()

add BC support usage of DataTransformerResolver

Update tests/Action/SetObjectFieldValueActionTest.php

Update tests/Form/DataTransformer/BooleanToStringTransformerTest.php

Update tests/Form/DataTransformerResolverTest.php

Update src/Action/SetObjectFieldValueAction.php

change "entity" word to "model" in documentations

change deprecated error message

add datetime in editable date form types

correct test transform datetime and date form types

test DateTime object in assertSame()

fix typo

restore getTemplate() return value in SetObjectFieldValueActionTest

use Yoda conditions

lazy-load predefined data transformers

add DataTransformerResolverInterface

use constants for determinate a field type

test laze-load data transformers

test usage DataTransformerResolver::addCustomGlobalTransformer()

create simple function in DataTransformerResolverTest

Process deprecation of FieldDescriptionInterface::getTargetEntity()

Use FieldDescriptionInterface::getTargetModel if exists sonata-project#6208

change usage getTargetEntity() -> getTargetModel() in DataTransformerResolverTest

merge changes from PR sonata-project#6167

register BooleanToStringTransformer as a service

merge changes from PR sonata-project#6144
peter-gribanov added a commit to peter-gribanov/SonataAdminBundle that referenced this pull request Sep 4, 2020
allow use data_transformer in SetObjectFieldValueAction

create BooleanToStringTransformer for allows to use non-strings

update SetObjectFieldValueActionTest

use yoda conditions

fix errors in HelperControllerTest

test BooleanToStringTransformer

allow override transformers for 'date', 'boolean' and 'choice' field types

mark BooleanToStringTransformer and BooleanToStringTransformer classes as final

add example of using the data_transformer option in docs

add full docs about Symfony Data Transformers

optimize resolve Data Transformer

fix docs

create DataTransformerResolver service

add type hint for BooleanToStringTransformer::$trueValue

allow add a custom global transformers

field type should be a string

correct default value for $globalCustomTransformers

correct test DataTransformerResolverTest::testAddCustomGlobalTransformer()

add BC support usage of DataTransformerResolver

Update tests/Action/SetObjectFieldValueActionTest.php

Update tests/Form/DataTransformer/BooleanToStringTransformerTest.php

Update tests/Form/DataTransformerResolverTest.php

Update src/Action/SetObjectFieldValueAction.php

change "entity" word to "model" in documentations

change deprecated error message

add datetime in editable date form types

correct test transform datetime and date form types

test DateTime object in assertSame()

fix typo

restore getTemplate() return value in SetObjectFieldValueActionTest

use Yoda conditions

lazy-load predefined data transformers

add DataTransformerResolverInterface

use constants for determinate a field type

test laze-load data transformers

test usage DataTransformerResolver::addCustomGlobalTransformer()

create simple function in DataTransformerResolverTest

Process deprecation of FieldDescriptionInterface::getTargetEntity()

Use FieldDescriptionInterface::getTargetModel if exists sonata-project#6208

change usage getTargetEntity() -> getTargetModel() in DataTransformerResolverTest

merge changes from PR sonata-project#6167

register BooleanToStringTransformer as a service

merge changes from PR sonata-project#6144

Move internal configuration to PHP sonata-project#6284
peter-gribanov added a commit to peter-gribanov/SonataAdminBundle that referenced this pull request Sep 4, 2020
allow use data_transformer in SetObjectFieldValueAction

create BooleanToStringTransformer for allows to use non-strings

update SetObjectFieldValueActionTest

use yoda conditions

fix errors in HelperControllerTest

test BooleanToStringTransformer

allow override transformers for 'date', 'boolean' and 'choice' field types

mark BooleanToStringTransformer and BooleanToStringTransformer classes as final

add example of using the data_transformer option in docs

add full docs about Symfony Data Transformers

optimize resolve Data Transformer

fix docs

create DataTransformerResolver service

add type hint for BooleanToStringTransformer::$trueValue

allow add a custom global transformers

field type should be a string

correct default value for $globalCustomTransformers

correct test DataTransformerResolverTest::testAddCustomGlobalTransformer()

add BC support usage of DataTransformerResolver

Update tests/Action/SetObjectFieldValueActionTest.php

Update tests/Form/DataTransformer/BooleanToStringTransformerTest.php

Update tests/Form/DataTransformerResolverTest.php

Update src/Action/SetObjectFieldValueAction.php

change "entity" word to "model" in documentations

change deprecated error message

add datetime in editable date form types

correct test transform datetime and date form types

test DateTime object in assertSame()

fix typo

restore getTemplate() return value in SetObjectFieldValueActionTest

use Yoda conditions

lazy-load predefined data transformers

add DataTransformerResolverInterface

use constants for determinate a field type

test laze-load data transformers

test usage DataTransformerResolver::addCustomGlobalTransformer()

create simple function in DataTransformerResolverTest

Process deprecation of FieldDescriptionInterface::getTargetEntity()

Use FieldDescriptionInterface::getTargetModel if exists sonata-project#6208

change usage getTargetEntity() -> getTargetModel() in DataTransformerResolverTest

merge changes from PR sonata-project#6167

register BooleanToStringTransformer as a service

merge changes from PR sonata-project#6144

Move internal configuration to PHP sonata-project#6284
peter-gribanov added a commit to peter-gribanov/SonataAdminBundle that referenced this pull request Sep 7, 2020
allow use data_transformer in SetObjectFieldValueAction

create BooleanToStringTransformer for allows to use non-strings

update SetObjectFieldValueActionTest

use yoda conditions

fix errors in HelperControllerTest

test BooleanToStringTransformer

allow override transformers for 'date', 'boolean' and 'choice' field types

mark BooleanToStringTransformer and BooleanToStringTransformer classes as final

add example of using the data_transformer option in docs

add full docs about Symfony Data Transformers

optimize resolve Data Transformer

fix docs

create DataTransformerResolver service

add type hint for BooleanToStringTransformer::$trueValue

allow add a custom global transformers

field type should be a string

correct default value for $globalCustomTransformers

correct test DataTransformerResolverTest::testAddCustomGlobalTransformer()

add BC support usage of DataTransformerResolver

Update tests/Action/SetObjectFieldValueActionTest.php

Update tests/Form/DataTransformer/BooleanToStringTransformerTest.php

Update tests/Form/DataTransformerResolverTest.php

Update src/Action/SetObjectFieldValueAction.php

change "entity" word to "model" in documentations

change deprecated error message

add datetime in editable date form types

correct test transform datetime and date form types

test DateTime object in assertSame()

fix typo

restore getTemplate() return value in SetObjectFieldValueActionTest

use Yoda conditions

lazy-load predefined data transformers

add DataTransformerResolverInterface

use constants for determinate a field type

test laze-load data transformers

test usage DataTransformerResolver::addCustomGlobalTransformer()

create simple function in DataTransformerResolverTest

Process deprecation of FieldDescriptionInterface::getTargetEntity()

Use FieldDescriptionInterface::getTargetModel if exists sonata-project#6208

change usage getTargetEntity() -> getTargetModel() in DataTransformerResolverTest

merge changes from PR sonata-project#6167

register BooleanToStringTransformer as a service

merge changes from PR sonata-project#6144

merge changes from PR sonata-project#6284

compare date with time in DataTransformerResolverTest
VincentLanglet pushed a commit that referenced this pull request Sep 13, 2020
allow use data_transformer in SetObjectFieldValueAction

create BooleanToStringTransformer for allows to use non-strings

update SetObjectFieldValueActionTest

use yoda conditions

fix errors in HelperControllerTest

test BooleanToStringTransformer

allow override transformers for 'date', 'boolean' and 'choice' field types

mark BooleanToStringTransformer and BooleanToStringTransformer classes as final

add example of using the data_transformer option in docs

add full docs about Symfony Data Transformers

optimize resolve Data Transformer

fix docs

create DataTransformerResolver service

add type hint for BooleanToStringTransformer::$trueValue

allow add a custom global transformers

field type should be a string

correct default value for $globalCustomTransformers

correct test DataTransformerResolverTest::testAddCustomGlobalTransformer()

add BC support usage of DataTransformerResolver

Update tests/Action/SetObjectFieldValueActionTest.php

Update tests/Form/DataTransformer/BooleanToStringTransformerTest.php

Update tests/Form/DataTransformerResolverTest.php

Update src/Action/SetObjectFieldValueAction.php

change "entity" word to "model" in documentations

change deprecated error message

add datetime in editable date form types

correct test transform datetime and date form types

test DateTime object in assertSame()

fix typo

restore getTemplate() return value in SetObjectFieldValueActionTest

use Yoda conditions

lazy-load predefined data transformers

add DataTransformerResolverInterface

use constants for determinate a field type

test laze-load data transformers

test usage DataTransformerResolver::addCustomGlobalTransformer()

create simple function in DataTransformerResolverTest

Process deprecation of FieldDescriptionInterface::getTargetEntity()

Use FieldDescriptionInterface::getTargetModel if exists #6208

change usage getTargetEntity() -> getTargetModel() in DataTransformerResolverTest

merge changes from PR #6167

register BooleanToStringTransformer as a service

merge changes from PR #6144

merge changes from PR #6284

compare date with time in DataTransformerResolverTest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants