Reputation: 159
Is there a way to configure chessboard.js so that only the white pieces can be moved by the user?
Upvotes: 2
Views: 697
Reputation: 21
I don't know if this is still relevant 3 years later but you could try something like this:
if (piece.search(/^w/) === -1) {
cfg.draggable = false;
}
I used something similar in my chess puzzle web page to stop all pieces movement when the puzzle is over and it works actually quite well.
Upvotes: 0
Reputation: 28611
Pretty sure the example can be adapted quite easily:
http://chessboardjs.com/examples#4002
Adapted code:
var onDragStart = function(source, piece, position, orientation) {
// if it's not white, don't allow drag
if (piece.search(/^w/) === -1) ||
return false;
}
};
var cfg = {
draggable: true,
position: 'start',
onDragStart: onDragStart
};
var board = ChessBoard('board', cfg);
Or just use the example in the documentation as-is, but don't change the orientation of the board.
Upvotes: 3