Comments (1)
OK, let me answer my own question. :) This is my current approach:
inc/sample.php
(or your custom file): Add custom paramater req in fields array to fields that you wish to be required and set it to true. Such as:
array( // Text Input 'label' => 'Text Input', // 'desc' => 'A description for the field.', // description 'id' => $prefix.'text', // field id and name 'type' => 'text' // type of field 'req' => true // CUSTOM REQ PARAMETER ),
meta_box.php
: Get the data and set new variable (basically repeat pattern from lines 20 to 28).
$req = isset($field['req']) ? $field['req'] : null;
meta_box.php
: Run another case/switch statement and do whatever you want to do with the results.
switch($req) { case 'true': echo' This is required.'; break; }
meta_box.php
/optional/: I like to add "req" and "unreq" class to table rows to be able to do some fancy jQuery validation magic.
function meta_box_callback() {
// Nonce
// Begin the field table and loop
echo '<table class="form-table meta_box">';
foreach ( $this->fields as $field) {
if (isset($field['req'])) { $req = 'req'; } else { $req = 'unreq'; } // required check (cibulka)
if ( $field['type'] == 'section' ) {
// req class (cibulka)
echo '<tr class="'.$req.'">[...]</tr >';
} else {
// req class (cibulka)
echo '<tr class="'.$req.'">[...]</tr>';
}
} // end foreach
echo '</table>'; // end table
}
Does it make sense?
SIDENOTE (for PHP beginners like me): I like to add comments to code, that clearly state what are my edits of default library. You can cmd+F you edits easily, which is essential for debugging (you never know what you can mess up) and updating.
from reusable-custom-wordpress-meta-boxes.
Related Issues (20)
- Adding fields to existing Metabox items. HOT 1
- Can no longer support this repo HOT 7
- Prevent HTML tag strip
- Numeric Value after uploading image. HOT 8
- Using fields HOT 15
- Use it in my own custom page
- Fatal error: Class 'custom_add_meta_box' not found HOT 1
- How to use Reusable Custom fields from a mu-plugins.php? HOT 3
- How to get field data?
- Image Uploader doesn't work... HOT 1
- Image Uploader no longer working in 3.8. HOT 1
- File Uploader isn't saving file URL
- Repeatable Image Isn't working
- Add a metabox to a specific page (with a page-template) HOT 1
- Bug with only custom post types???..
- how to store data from the fields within Repeatable...
- Multiple on selectbox doesn't work
- tax_select in repeatable fieds
- Turkish Character Problem Repeatable Textarea
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reusable-custom-wordpress-meta-boxes.