-
Notifications
You must be signed in to change notification settings - Fork 920
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
[Feature] Enable Unique Checks via Ajax #136
Conversation
I like this, I like this a lot, the interface is perfect, I think. But since is not a "core" function, I'm wondering if this is the best way to implement this (because there's no going back if we do). Here's what I think the problems are and my proposed solutions: Problem 1. We have logic from one field type inside general-purpose files This would make the CRUD more difficult to understand and overwrite for users that don't use that functionality (which will probably be a majority). I think a better approach to this would be a separate field type,
Problem 2. CrudController got really really big and includes both core and non-core methods As Laravel suggests (the blue notice): I think the best approach for this would be to:
That would both allow the user to overwrite the method in their EntityCrudController AND separate a non-core functionality from CrudController. I think we'll end up using this procedure a lot, including for already-posted functionalities (like
I think this would not constitute a breaking change if we Problem 3. We register yet another route for all CRUDs, whether or not it's used To sum up and see if this is a good idea, the instructions for the
What do you think? Does this make for a cleaner framework? I don't think the added steps for this functionality are that much of a drag. Only a few CRUD panels would need this. |
|
Problem 5. Are there use cases for a more general functionality? We could do that by passing a model method to the field. So you'd add a field where, as the user types, a certain method on the model is checked. That method would either return true or false. So the field could be: $this->crud->addField([
'label' => 'Product Slug',
'name' => 'slug',
'type' => 'text',
'ajaxCheck' => 'slugExists',
'ajaxCheckErrorMessage' => 'This slug already exists',
]); and it would send an AJAX POST request to But the question is: are there actual usecases or is it overoptimization? |
Problem 5 eh? Jumping 4? :D I did actually think about making it more generic so you pass the method/route to check, which would be a nice feature, however I found unique checks were as far as I'd needed to go, with things like usernames, urls, emails, access codes, api keys etc etc. Maybe if it's implemented in such a way that allows the future possibilities it would be nice, just start with a generic $this->crud->addField([
'label' => 'Product Slug',
'name' => 'slug',
'type' => 'text',
'ajaxCheck' => 'unique',
'ajaxCheckErrorMessage' => 'This slug already exists',
]); which intern hits |
[now replying to your 3-point message above]
Eager to find out what you think about the general approach. |
:-)) my bad. It was problem 4. Yes, I agree, unique should come pre-built, because it will probably be the most used. And we can easily do that by having a method inside CrudTrait, because all models already use it: public function columnValueExists($column, $value) {
// check that column for that value
// return true/false
} I'm not sure this is a good name for it, but I think "unique" might be too common. Then someone might create a "unique()" method on his model and overwrite this one my mistake. I think this has really really progressed. This has been a very good back-and-forth and the end result might be an excellent new feature. I do think we should let it sink in for a day or so, see if we think differently or come up with a better approach. I guess pushing features into open-source projects is like unprotected sex: it's very gratifying, but you can't take it back if you don't like the outcome :-)) |
1. I think for the time being "string" based checks will be okay, so we can still keep the icon indicators within the text fields, as even things like emails etc will still show the same field, what other fields did you think would be an issue? 3. I can't see the documentation anywhere for 4. Sure, any thing like that ColumnValueUnique/Exists - I think we'd need to consider what the user is expected to return, for example ColumnValueExists return true/false - then means we need to figure out what that model is and return it to the view for the user to see it in the info box, so we need to make sure its easy enough for users to customise the response to the view |
[ci skip] [skip ci]
@tabacitu I've pushed some changes, not entirely sure how to implement the |
@tabacitu this is also helpful :D |
Definitely a must-have feature, especially the broader version with the Model function. Is the merge of this feature still planned? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spacing around ifs and functions are dubious throughout.
protected $options = null; | ||
protected $controller = null; | ||
|
||
public function __construct($name, $controller, $options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation.
$this->controller = $controller; | ||
} | ||
|
||
public function with($injectables) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation.
|
||
public function with($injectables) | ||
{ | ||
if (is_string($injectables)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this weed out the undefineds?
return $this->inject(); | ||
} | ||
|
||
private function inject() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation.
} | ||
} | ||
|
||
public function __call($method, $parameters = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation.
//lookup field | ||
function checkUnicity() | ||
{ | ||
//only look it up if its actually changed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's
}, null, 'json') | ||
.then(function( response ){ | ||
$icon.removeClass(classList).removeClass('fa-pencil'); | ||
if( response.success || response.meta.entity_key == $entityKey){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces
} else { | ||
$icon.addClass('fa-times'); | ||
|
||
if( $uniqueConfig.hint ){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces. Remove the new line.
|
||
var msg = response.message; | ||
|
||
if( response.meta && response.meta.link ){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces.
} | ||
} | ||
|
||
}, function( response ){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces
@OwenMelbz - I think I'm going to close this, unfortunately. It's a cool functionality, but it breaks away from how CRUD does stuff usually, and I think that's a bad thing. I think we'll come back to this when Create/Edit forms will be AJAX, in the next major version - it will I do think this PR brought up some serious architecture issues, though, thank you for that, we should seriously keep it in mind in the next major version. Cheers! |
summary
Enables fields to be marked as unique, giving the user visual feedback as they type, with an optional hint
preview

usage